1.\" $OpenBSD: pkg_add.1,v 1.168 2024/10/02 09:14:08 tb Exp $ 2.\" 3.\" Documentation and design originally from FreeBSD. All the code has 4.\" been rewritten since. We keep the documentation's notice: 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" Jordan K. Hubbard 16.\" 17.\" 18.Dd $Mdocdate: October 2 2024 $ 19.Dt PKG_ADD 1 20.Os 21.Sh NAME 22.Nm pkg_add 23.Nd install or update software packages 24.Sh SYNOPSIS 25.Nm pkg_add 26.Bk -words 27.Op Fl acIimnqrsUuVvxz 28.Op Fl A Ar arch 29.Op Fl B Ar pkg-destdir 30.Op Fl D Ar name Ns Op = Ns Ar value 31.Op Fl L Ar localbase 32.Op Fl l Ar file 33.Op Fl P Ar type 34.Op Ar pkg-name ... 35.Ek 36.Sh DESCRIPTION 37The 38.Nm 39command is used to install or update 40.Xr packages 7 41created from the 42.Xr ports 7 43tree. 44.Bd -filled -offset indent 45.Em Note : 46System distribution files, e.g., base71.tgz, comp71.tgz, are 47.Em not 48packages and may not be installed using 49.Nm . 50.Ed 51.Pp 52By default, 53.Nm 54rejects unsigned packages unless they come from a trusted source 55.Po 56.Ev TRUSTED_PKG_PATH 57.Pc 58or option 59.Fl D Cm unsigned 60is used. 61.Pp 62If a package is signed: 63.Bl -bullet 64.It 65.Nm 66checks that its signature is valid and that the signature was 67emitted by a valid signing key, as stored in 68.Pa /etc/signify/*-pkg.pub , 69.It 70.Nm 71verifies that the compressed package data matches the signature, before 72it decompresses and unpacks files 73.Po 74see 75.Xr signify 1 76in 77.Fl z 78mode 79.Pc . 80.El 81.Pp 82.Nm 83can be used to 84.Bl -bullet 85.It 86Install new packages. 87This is the normal mode. 88The 89.Ar pkg-name ... 90specified on the command line are new package names to install. 91.It 92Update installed packages, using option 93.Fl u . 94Optional 95.Ar pkg-name ... 96may be specified on the command line, as names of packages already installed 97on the machine, to be updated to new versions along with their dependencies. 98If no name is specified, all the packages will be updated. 99.It 100Install new packages in a hurry, updating their dependencies first, 101using option 102.Fl U . 103The 104.Ar pkg-name ... 105specified on the command line are new packages that may require updating 106dependencies first. 107It is recommended to keep all packages in-synch 108with 109.Fl u 110whenever possible, but 111.Fl U 112can be much faster. 113.It 114Replace existing packages with explicit other versions, using option 115.Fl r . 116The 117.Ar pkg-name ... 118specified on the command line are new packages that should replace 119already installed packages, with other versions or flavors. 120.El 121.Pp 122.Nm 123relies on the file system information being consistent. 124In case of a system crash, 125.Pa /var/db/pkg 126may become corrupted. 127Use 128.Xr pkg_check 8 129to repair things. 130.Pp 131Details of packing-list internals are documented in 132.Xr pkg_create 1 . 133.Pp 134.Nm 135will 136.Xr syslog 3 137installations and updates by default. 138.Pp 139Each package name may be specified as a filename (which normally consists of the 140package name itself plus the 141.Dq .tgz 142suffix) or a URL referring to FTP, HTTP, HTTPS, or SCP locations. 143If the given package names are not found in the current working directory, 144.Nm 145will search for them in each directory (local or remote) named by the 146.Ev TRUSTED_PKG_PATH 147environment variable, 148then the 149.Ev PKG_PATH 150environment variable. 151The special url 152.Sq installpath 153refers to the contents of 154.Xr installurl 5 . 155If neither 156.Ev TRUSTED_PKG_PATH 157nor 158.Ev PKG_PATH 159are defined, 160.Nm 161will use 162.Sq ./:installpath 163as a default. 164.Pp 165.Nm 166also understands 167.Sq stems , 168that is, package names without any version specification. 169For instance, with 170.Sq Nm Ar kdelibs , 171.Nm 172will look in the current directory 173.Po 174or the 175.Ev PKG_PATH 176.Pc 177for a 178.Ar kdelibs 179package. 180.Pp 181.Nm 182may ask questions in interactive mode, or error out otherwise. 183Interactive mode is the default on a tty, see 184options 185.Fl I/i . 186.Pp 187For instance 188.Sq Nm Ar vim 189is ambiguous as it matches 190.Ar vim-*-no_x11 , 191.Ar vim-*-gtk3 , 192and a few other flavors. 193.Pp 194To avoid ambiguities, 195.Nm 196supports 197.Sq stems with flavors , 198that is, a stem separated from flavors with a double dash. 199For instance, the previous ambiguity could be resolved by using 200.Sq Nm Ar vim--no_x11 201(matches only the no_x11 flavor) 202or 203.Sq Nm Ar vim--gtk3 204(matches only the gtk3 flavor). 205.Pp 206There is also an ambiguity related to ports with multiple branches. 207For instance 208.Sq Nm Ar python 209is ambiguous, as there are several versions of python in the ports tree. 210So is 211.Sq Nm Ar postfix . 212The special form 213.Sq Ar pkgname Ns % Ns Ar branch 214can be used to restrict matches to a branch matching the 215.Xr pkgpath 7 . 216.Pp 217The above ambiguities can be resolved using 218.Sq Nm Ar postfix Ns % Ns Ar stable 219and 220.Sq Nm Ar python Ns % Ns Ar 3.9 , 221respectively. 222.Pp 223All paths recognize certain special sequences, 224which are expanded as follows: 225.Bl -tag -width "%m" 226.It %a 227The package architecture as returned by 228.Xr arch 1 229.Fl s . 230.It %v 231The operating system version in the format 232.Dq digit dot digit . 233.It %c 234Expands to the string 235.Qq snapshots 236when running a -current or -beta kernel, or if the command line option 237.Fl D Cm snap | Fl D Cm snapshot 238is specified. 239Otherwise, %c expands to %v, which selects a release version. 240.It %m 241The full mirror path, 242.Qq /pub/OpenBSD/%c/packages/%a/ . 243.El 244.Pp 245If the resulting path contains 246.Qq %c/packages 247and %c is not 248.Qq snapshots , 249then a second directory is also searched, which is constructed by replacing 250.Qq packages 251with 252.Qq packages-stable . 253.Pp 254The following examples are valid: 255.Bd -literal -offset indent 256pkg_add -v http://ftp.openbsd.org/%m/rsync-- 257pkg_add -v http://ftp.openbsd.org/%m/m4 258pkg_add -v scp://login@host/usr/ports/packages/%a/all/tcl%8.5 259.Ed 260.Pp 261If the environment variable 262.Ev PKG_CACHE 263is set to a directory name, every package retrieved from a distant location 264will also be copied here. 265.Pp 266If the environment variable 267.Ev DEBUG_PKG_CACHE 268is set to a directory name, debug packages matching installed/updated packages 269will be downloaded to that directory 270.Po 271this is to avoid 272.Sq shearing , 273as later on, you might wish to debug software, but the snapshots will have 274moved on and the debug packages no longer match your installation 275.Pc . 276This only applies to debug packages that are not currently installed/updated. 277.Pp 278Some packages may depend on other packages. 279When resolving dependencies 280.Nm 281will first look at already installed packages, then match 282dependencies with the list of packages left to install, then ask the 283user's opinion in interactive mode, 284then install default packages that satisfy the dependencies. 285.Pp 286.Sy Warning : 287Since 288.Nm 289may execute scripts or programs contained within a package file, 290your system may be susceptible to 291.Dq trojan horses 292or other subtle attacks from miscreants who create dangerous packages. 293Be sure the specified package(s) are from trusted sources. 294.Pp 295The options are as follows: 296.Bl -tag -width keyword 297.It Fl A Ar arch 298Assume 299.Ar arch 300as current machine architecture for any package tests. 301.It Fl a 302Automated package installation; do not record packages as installed manually. 303.It Fl aa 304Force already installed packages to be tagged as installed automatically. 305.It Fl B Ar pkg-destdir 306Set 307.Ar pkg-destdir 308as the prefix to prepend to any object extracted from the package. 309.It Fl c 310While replacing packages, delete extra configuration file in the old package, 311mentioned as 312.Dl @extra file 313in the packing-list. 314.It Fl D Ar name Ns Op = Ns Ar value 315Force installation of the package. 316.Ar name 317is a keyword that states what failsafe 318should be waived. 319Recognized keywords include: 320.Pp 321.Bl -tag -width "updatedependsXX" -compact 322.It Cm allversions 323Do not trim older p* variants of packages for updates. 324.It Cm arch 325Architecture recorded in package may not match. 326.It Cm checksum 327Verify checksums before deleting or tying old files. 328.It Cm dontmerge 329By default, if dependencies are too strict, 330.Nm 331will merge updates together to make sure everything stays in sync. 332.Fl D Ns Cm dontmerge 333disables that behavior. 334.It Cm donttie 335By default, 336.Nm 337will try to find new files in old packages by comparing the stored sha256, 338and tie the entries together to avoid extracting files needlessly. 339.Fl D Ns Cm donttie 340disables that behavior. 341.It Cm downgrade 342Don't filter out package versions older than what's currently installed. 343.It Cm installed 344In update mode, reinstall an existing package with the same update signature. 345.It Cm nonroot 346Install even if not running as root. 347.It Cm repair 348Attempt to repair installed packages with missing registration data. 349.It Cm scripts 350External scripts may fail. 351.It Cm SIGNER 352List of trusted signers, separated by commas. 353Corresponds to list of public keys under 354.Pa /etc/signify 355we want to trust. 356Defaults to any key matching 357.Sq *pkg . 358.It Cm snap | Cm snapshot 359Force 360.Sq %c 361and 362.Sq %m 363to expand to 364.Sq snapshots , 365even on a release kernel. 366.It Cm unsigned 367Allow the installation of unsigned packages without warnings/errors. 368But see 369.Ev TRUSTED_PKG_PATH , 370which is more discriminating. 371.It Cm updatedepends 372Force update even if dependencies no longer match. 373.El 374.It Fl I 375Force non-interactive mode. 376Default is to be interactive when run from a tty. 377.It Fl i 378Force interactive mode, even if not run from a tty. 379.Nm 380may ask questions to the user if faced with difficult decisions. 381.It Fl L Ar localbase 382Install a package under 383.Ar localbase . 384By default, 385.Ar localbase 386equals 387.Pa /usr/local , 388and specifying it is not necessary. 389However, packages can be created using a different 390.Ar localbase 391.Po 392see 393.Xr pkg_create 1 394.Pc , 395and those packages can only be installed by using the same 396.Ar localbase . 397See 398.Xr bsd.port.mk 5 399for a description of 400.Ev LOCALBASE . 401.It Fl l Ar file 402Installs packages from the raw output of 403.Xr pkg_info 1 , 404as saved in 405.Ar file . 406Generally, to reproduce an installation from machine to machine, 407use 408.Li pkg_info -mz \*(Gtinstalled_list 409on the source machine and 410.Li pkg_add -l installed_list 411on the destination machine. 412.It Fl m 413Causes 414.Nm 415to always display the progress meter in cases it would not do so by default. 416.It Fl n 417Don't actually install a package, just report the steps that 418would be taken if it was. 419Will still copy packages to 420.Ev PKG_CACHE 421if applicable. 422.It Fl P Ar ftp 423Check that package can be distributed on ftp. 424.It Fl qq 425Do not bother with checksums for configuration files. 426.It Fl r 427Replace existing packages. 428.It Fl s 429Don't actually install packages, skip as many steps as needed and report 430only the disk size changes that would happen. 431Similar to 432.Fl n , 433except it also skips fetching full packages and stops at getting the 434information it needs. 435.It Fl U 436Update dependencies if required before installing the new package(s). 437.It Fl u 438Update the given installed 439.Ar pkgname(s) , 440and anything it depends upon. 441If no 442.Ar pkgname 443is given, 444.Nm 445will update all installed packages. 446This relies on 447.Ev PKG_PATH 448to figure out the new package names. 449.It Fl V 450Displays the number of packages done/total number of packages. 451.It Fl v 452Turn on verbose output. 453Several 454.Fl v 455turn on more verbose output. 456By default, 457.Nm 458is almost completely silent, but it reacts to keyboard status requests 459.Po 460see 461.Xr stty 1 462.Pc . 463.Fl v 464turns on basic messages, 465.Fl vv 466adds relevant system operations, 467.Fl vvv 468shows most internal computations apart from individual file/directory 469additions, 470.Fl vvvv 471also shows dependencies adjustments, and 472.Fl vvvvv 473shows everything. 474.It Fl x 475Disable progress meter. 476.It Fl z 477Fuzzy package addition: 478.Nm 479will do its best to match package names passed on the command line, 480even if the versions don't match and it will proceed even if 481some packages can't be found. 482.El 483.Pp 484By default, when adding packages via FTP, the 485.Xr ftp 1 486program operates in 487.Dq passive 488mode. 489If you wish to use active mode instead, set the 490.Ev FTPMODE 491environment variable to 492.Dq active . 493If 494.Nm 495consistently fails to fetch a package from a site known to work, 496it may be because the site does not support 497passive mode FTP correctly. 498This is very rare since 499.Nm 500will try active mode FTP if the server refuses a passive mode 501connection. 502.Ss Manual installation 503.Nm 504differentiates between packages specified on the command line, and packages 505installed automatically because of inter-dependencies: 506the first kind will be tagged as 507.Sq installed manually . 508The 509.Fl a 510option is used internally by the 511.Xr ports 7 512infrastructure 513and 514.Xr dpb 1 515to handle dependencies. 516.Pp 517It is also possible to tweak the 518.Sq installed manually 519status of a package after the fact. 520Running 521.Nm 522on an already installed package will tag it as 523.Sq installed manually , 524even if it was already there as a dependency of something else, 525and doubling the 526.Fl a 527option will remove the 528.Sq installed manually 529tag from installed packages. 530.Pp 531.Xr pkg_info 1 532can be used to show only manually-installed packages, and 533.Xr pkg_delete 1 534can be used to remove dependencies when they are no longer needed. 535.Ss Technical details 536.Nm 537deals with 538.Sq updatesets 539internally. 540An updateset is a collection of old package(s) to delete, and new package(s) 541to install, as an atomic operation. 542Under normal circumstances, an updateset contains at most one old package 543and one new package, but some situations may require 544.Nm 545to perform several installations/deletions at once. 546.Pp 547For each new package in an updateset, 548.Nm 549extracts the package's 550.Dq packing information 551(the packing-list and description mostly) 552into a special staging directory under 553.Pa /tmp 554(or 555.Ev PKG_TMPDIR 556if set) 557and then runs through the following sequence to fully extract the contents 558of the package: 559.Bl -enum 560.It 561A check is made to determine if the package is already recorded as installed. 562If it is, 563the installation is terminated. 564.It 565A check is made to determine if the package conflicts (from 566.Cm @conflict 567directives; see 568.Xr pkg_create 1 ) 569with a package already recorded as installed. 570In non-replacement mode, its installation is terminated. 571.It 572For packages tagged with architecture constraints, 573.Nm 574verifies that the current machine architecture agrees with the constraints. 575.It 576All package dependencies (from 577.Cm @depend 578and 579.Cm @wantlib 580directives; see 581.Xr pkg_create 1 ) 582are read from the packing-list. 583If any of these dependencies are not currently fulfilled, 584an attempt is made to find a package that meets them and install it, 585looking first in the current updateset, then in the list of packages 586to install passed to 587.Nm ; 588if no adequate package can be found and installed, 589the installation is terminated. 590.It 591.Nm 592checks for collisions with installed file names, read-only file systems, 593and enough space to store files. 594.It 595The packing-list is used as a guide for extracting 596files from the package into their final locations. 597.It 598After installation is complete, a copy of all package files 599such as the packing-list, extra messages, or 600the description file is made into 601.Pa /var/db/pkg/<pkg-name> 602for subsequent possible use by 603.Xr pkg_delete 1 604and 605.Xr pkg_info 1 . 606Any package dependencies are recorded in the other packages' 607.Pa /var/db/pkg/<other-pkg>/+REQUIRED_BY 608file 609(if the environment variable 610.Ev PKG_DBDIR 611is set, this overrides the 612.Pa /var/db/pkg/ 613path shown above). 614.It 615Finally, the staging area is deleted and the program terminates. 616.El 617.Pp 618Note that it is safe to interrupt 619.Nm pkg_add 620through 621.Dv SIGINT , 622.Dv SIGHUP , 623and other signals, as it will safely record an interrupted install as 624.Pa partial-<pkgname>[.n] . 625.Pp 626When replacing packages, the procedure is slightly different. 627.Bl -enum 628.It 629A check is made to determine if a similar package is already installed. 630If so, its full update signature is computed, which contains all the 631necessary dependency information along with the actual package version. 632If that signature is identical to that of the new package, no replacement 633is performed (unless 634.Fl D Cm installed 635is specified). 636.It 637A check is made to determine what old package(s) the new package(s) should 638replace, using conflicts. 639.Nm 640will attempt to update those packages. 641If they update to the new package(s), nothing needs to be done. 642If they're part of the list of updatesets to install, the corresponding 643updatesets will be merged. 644Otherwise, 645.Nm 646will add them to the current updateset, and rerun update to find suitable 647updates to those packages. 648.It 649A check is made to determine whether the old packages will be deleted without 650issue, and whether the new packages will install correctly. 651This includes verifying 652that the new package still matches dependencies (unless 653.Fl D Cm updatedepends ) . 654.It 655Shared libraries deserve special treatment: each shared library from the old 656packages that does no longer exist in the new packages, but that is required 657from a wantlib of another package is kept along in a stub package named 658.Pa \&.libs-<pkgname> . 659.It 660.Nm 661uses sha256 checksums to avoid extracting too much: if a file from an 662old package didn't change, it will be reused verbatim, and the extraction 663will often finish early. 664.It 665The new packages are extracted to the filesystem, using temporary filenames 666of the form 667.Pa pkg.XXXXXXX 668if necessary to avoid conflicts with the old packages. 669The packing-list is amended to record these names as @temp annotations, 670in cases the installation fails. 671.It 672The old packages are deleted as usual, except that some packages may still 673depend on them. 674Note also that 675.Cm @unexec-delete 676commands are not executed. 677.It 678The new packages are installed as usual, except that the files are already 679present and only need to be renamed. 680Note also that 681.Cm @exec-add 682commands are not executed. 683.It 684Dependencies from the old packages are adjusted to point to the correct new 685package. 686.El 687.Pp 688To update packages in -u mode, 689.Nm 690performs the following steps. 691.Bl -enum 692.It 693Each package name is reduced to its stem, and every package name with matching 694stem available through 695.Ev PKG_PATH 696is considered as an update candidate. 697.It 698.Nm 699searches for a 700.Sq quirks 701package first, which may contain exceptions to these rules. 702This special package contains global information, such as packages that 703can be deleted because they're now part of base, or stem changes. 704.It 705Version matching occurs: unless 706.Fl D Cm downgrade , 707only packages with newer 708versions will be considered as update candidates. 709Note that version matching is costly, thus 710.Ev PKG_PATH 711should point to a snapshot of packages for a given version of 712.Ox , 713similar to the organization on the FTP sites. 714.It 715Candidates are then matched according to their pkgpaths 716.Po 717see 718.Xr pkgpath 7 719and 720.Xr pkg_create 1 721.Pc 722in order to weed out similar packages with distinct options. 723.It 724The update signature of the candidate is compared to the signature of the 725already installed package: identical signatures mean no update needed. 726.It 727If several candidates are left, 728.Nm 729will ask the user in interactive mode, and not perform the update in 730non-interactive mode. 731.It 732Once a suitable update candidate has been found, 733.Nm 734checks the package dependencies. 735If necessary, it will install or update them first. 736Once all dependencies are up to date, 737.Nm 738will update the package. 739.El 740.Sh ENVIRONMENT 741.Bl -tag -width PKG_CHECKSUM 742.It Ev DEBUG_PKG_CACHE 743If set, debug packages matching installed/updated packages will be downloaded 744to that directory as well. 745.It Ev FTPMODE 746Specifies whether 747.Xr ftp 1 748should operate in 749.Dq active 750or 751.Dq passive 752mode. 753The default is 754.Dq passive . 755.It Ev FETCH_CMD 756Override use of 757.Xr ftp 1 . 758Must point to a command that understands 759.Li ${FETCH_CMD} -o - url . 760.It Ev PKG_CACHE 761If set, any package retrieved from a distant location will be copied to 762that directory as well. 763.It Ev PKG_CHECKSUM 764If set, verify files checksums during deletion, exactly like 765.Fl D Ns Cm checksum . 766.It Ev PKG_DBDIR 767Where to register packages instead of 768.Pa /var/db/pkg . 769.It Ev PKG_PATH 770If a given package name cannot be found, 771the directories named by 772.Ev PKG_PATH 773are searched. 774It should contain a series of entries separated by colons. 775Each entry consists of a directory name. 776URL schemes such as FTP, HTTP, HTTPS, or SCP are also appropriate. 777The current directory may be indicated 778implicitly by an empty directory name, or explicitly by a single 779period 780.Pq Ql \&./ . 781Special sequences 782.Sq %a , 783.Sq %c , 784.Sq %m , 785.Sq %v 786will be expanded. 787.It Ev PKG_TMPDIR 788Temporary area where package information files will be extracted, instead of 789.Pa /tmp . 790.It Ev TRUSTED_PKG_PATH 791Same semantics as 792.Ev PKG_PATH , 793but it is searched before 794.Ev PKG_PATH 795and waives any kind of signature checking. 796.El 797.Sh FILES 798.Bl -tag -width /etc/installurl 799.It Pa /etc/installurl 800default mirror server for package download 801.It Pa /etc/signify/*-pkg.pub 802public keys for package verification with 803.Xr signify 1 804.It Pa /usr/local/ 805default file system to install packages in 806.It Pa /usr/local/share/doc/pkg-readmes/ 807.Ox Ns -specific 808information about individual packages 809.It Pa /var/db/pkg/ 810database of installed 811.Xr packages 7 812.El 813.Sh SEE ALSO 814.Xr ftp 1 , 815.Xr pkg_create 1 , 816.Xr pkg_delete 1 , 817.Xr pkg_info 1 , 818.Xr OpenBSD::Intro 3p , 819.Xr bsd.port.mk 5 , 820.Xr installurl 5 , 821.Xr package 5 , 822.Xr pkg_check 8 823.Sh AUTHORS 824.Bl -tag -width indent -compact 825.It An Jordan Hubbard 826Initial design. 827.It An Marc Espie 828Complete rewrite. 829.El 830