xref: /freebsd/usr.sbin/pkg/pkg.7 (revision d0ff5773cefaf3fa41b1be3e44ca35bd9d5f68ee)
1.\" Copyright (c) 2013 Bryan Drewery <bdrewery@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd April 29, 2025
26.Dt PKG 7
27.Os
28.Sh NAME
29.Nm pkg
30.Nd a utility for manipulating packages
31.Sh SYNOPSIS
32.Nm
33.Op Fl d
34.Ar command ...
35.Nm
36.Op Fl d
37.Cm add
38.Op Fl fy
39.Op Fl r Ar reponame
40.Ar pkg.pkg
41.Nm
42.Fl N
43.Nm
44.Op Fl 46d
45.Cm bootstrap
46.Op Fl fy
47.Op Fl r Ar reponame
48.Sh DESCRIPTION
49.Nm
50is the package management tool.
51It is used to manage local packages installed from
52.Xr ports 7
53and install/upgrade packages from remote repositories.
54.Pp
55To avoid backwards incompatibility issues, the actual
56.Xr pkg 8
57tool is not installed in the base system.
58The first time invoked,
59.Nm
60will bootstrap the real
61.Xr pkg 8
62from a remote repository.
63.Bl -tag
64.It Nm Ar command ...
65If
66.Xr pkg 8
67is not installed yet, it will be fetched, have its signature verified,
68installed, and then have the original command forwarded to it.
69If already installed, the command requested will be forwarded to the real
70.Xr pkg 8 .
71.It Nm Cm add Oo Fl fy Oc Oo Fl r Ar reponame Oc Ar pkg.pkg
72Install
73.Xr pkg 8
74from a local package instead of fetching from remote.
75If signature checking is enabled, then the correct signature file
76must exist and the signature valid before the package will be installed.
77If the
78.Fl f
79flag is specified, then
80.Xr pkg 8
81will be installed regardless if it is already installed.
82If the
83.Fl y
84flag is specified, no confirmation will be asked when bootstrapping
85.Xr pkg 8 .
86.Pp
87If a
88.Ar reponame
89has been specified, then the signature configuration for that repository will be
90used.
91.It Nm Fl N
92Do not bootstrap, just determine if
93.Xr pkg 8
94is actually installed or not.
95Returns 0 and the number of packages installed
96if it is, otherwise 1.
97.It Nm Oo Fl 46 Oc Cm bootstrap Oo Fl fy Oc \
98Oo Fl r Ar reponame Oc
99Attempt to bootstrap and do not forward anything to
100.Xr pkg 8
101after it is installed.
102With
103.Fl 4
104and
105.Fl 6 ,
106.Nm
107will force IPv4 or IPv6 respectively to fetch
108.Xr pkg 8
109and its signatures as needed.
110If the
111.Fl f
112flag is specified, then
113.Xr pkg 8
114will be fetched and installed regardless if it is already installed.
115If the
116.Fl y
117flag is specified, no confirmation will be asked when bootstrapping
118.Xr pkg 8 .
119.Pp
120If a
121.Ar reponame
122has been specified, then the configuration for that repository will be used.
123.El
124.Sh OPTIONS
125The following options are supported by
126.Nm :
127.Bl -tag -width indent
128.It Fl d, Fl -debug
129Show debug information.
130May be specified more than once to increase the level of detail.
131When specified twice,
132.Xr fetch 3
133debug output is enabled.
134.El
135.Sh CONFIGURATION
136Configuration varies in whether it is in a repository configuration file
137or the global configuration file.
138The default repository configuration for
139.Fx
140is stored in
141.Pa /etc/pkg/FreeBSD.conf ,
142and additional repository configuration files will be searched for in
143.Ev REPOS_DIR ,
144or
145.Pa /usr/local/etc/pkg/repos
146if it is unset.
147.Pp
148For bootstrapping,
149.Nm
150will process all repositories that it finds and use the last enabled repository
151by default.
152.Pp
153Repository configuration is stored in the following format:
154.Bd -literal -offset indent
155FreeBSD: {
156  url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
157  mirror_type: "srv",
158  signature_type: "none",
159  fingerprints: "/usr/share/keys/pkg",
160  enabled: yes
161}
162.Ed
163.Pp
164.Bl -tag -width signature_type -compact
165.It url
166Refer to
167.Dv PACKAGESITE
168in
169.Sx ENVIRONMENT
170.It mirror_type
171Refer to
172.Dv MIRROR_TYPE
173in
174.Sx ENVIRONMENT
175.It signature_type
176Refer to
177.Dv SIGNATURE_TYPE
178in
179.Sx ENVIRONMENT
180.It fingerprints
181Refer to
182.Dv FINGERPRINTS
183in
184.Sx ENVIRONMENT
185.It enabled
186Defines whether this repository should be used or not.
187Valid values are
188.Dv yes ,
189.Dv true ,
190.Dv 1 ,
191.Dv no ,
192.Dv false ,
193.Dv 0 .
194.El
195.Pp
196Global configuration can be stored in
197.Pa /usr/local/etc/pkg.conf
198in the following format:
199.Bd -literal -offset indent
200PACKAGESITE: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
201MIRROR_TYPE: "srv",
202SIGNATURE_TYPE: "none",
203FINGERPRINTS: "/usr/share/keys/pkg",
204ASSUME_ALWAYS_YES: "yes"
205REPOS_DIR: ["/etc/pkg", "/usr/local/etc/pkg/repos"]
206.Ed
207.Pp
208Reference
209.Sx ENVIRONMENT
210for each variable.
211.Sh ENVIRONMENT
212The following environment variables can be set to override the settings
213from the
214.Pa pkg.conf
215file used.
216.Bl -tag -width "ASSUME_ALWAYS_YES"
217.It Ev MIRROR_TYPE
218This defines which mirror type should be used.
219Valid values are
220.Dv SRV ,
221.Dv HTTP ,
222.Dv NONE .
223.It Ev ABI
224This defines the ABI for the package to be installed.
225Default ABI is determined from
226.Pa /bin/sh .
227.It Ev ASSUME_ALWAYS_YES
228If set, no confirmation will be asked when bootstrapping
229.Xr pkg 8 .
230.It Ev SIGNATURE_TYPE
231If set to
232.Dv FINGERPRINTS
233then a signature will be required and validated against known
234certificate fingerprints when bootstrapping
235.Xr pkg 8 .
236.It Ev FINGERPRINTS
237If
238.Sy SIGNATURE_TYPE
239is set to
240.Dv FINGERPRINTS
241this value should be set to the directory path where known fingerprints are
242located.
243.It Ev PACKAGESITE
244The URL that
245.Xr pkg 8
246and other packages
247will be fetched from.
248.It Ev REPOS_DIR
249Comma-separated list of directories that should be searched for repository
250configuration files.
251.El
252.Sh FILES
253Configuration is read from the files in the listed order.
254This path can be changed by setting
255.Ev REPOS_DIR .
256The last enabled repository is the one used for bootstrapping
257.Xr pkg 8 .
258.Bl -tag -width "/usr/local/etc/pkg/repos/*.conf"
259.It Pa /usr/local/etc/pkg.conf
260.It Pa /etc/pkg/FreeBSD.conf
261.It Pa /usr/local/etc/pkg/repos/*.conf
262.El
263.Sh EXAMPLES
264Some examples are listed here.
265The full list of available commands are available in
266.Xr pkg 8
267once it is bootstrapped.
268.Pp
269Search for a package:
270.Dl $ pkg search perl
271.Pp
272Install a package:
273.Dl % pkg install perl
274.Pp
275List installed packages:
276.Dl $ pkg info
277.Pp
278Upgrade from remote repository:
279.Dl % pkg upgrade
280.Pp
281List non-automatic packages:
282.Dl $ pkg query -e '%a = 0' %o
283.Pp
284List automatic packages:
285.Dl $ pkg query -e '%a = 1' %o
286.Pp
287Delete an installed package:
288.Dl % pkg delete perl
289.Pp
290Remove unneeded dependencies:
291.Dl % pkg autoremove
292.Pp
293Change a package from automatic to non-automatic, which will prevent
294.Xr pkg-autoremove 8
295from removing it:
296.Dl % pkg set -A 0 perl
297.Pp
298Change a package from non-automatic to automatic, which will make
299.Xr pkg-autoremove 8
300allow it be removed once nothing depends on it:
301.Dl % pkg set -A 1 perl
302.Pp
303Create package file from an installed package:
304.Dl % pkg create -o /usr/ports/packages/All perl
305.Pp
306Determine which package installed a file:
307.Dl $ pkg which /usr/local/bin/perl
308.Pp
309Audit installed packages for security advisories:
310.Dl $ pkg audit
311.Pp
312Check installed packages for checksum mismatches:
313.Dl # pkg check -s -a
314.Pp
315Check for missing dependencies:
316.Dl # pkg check -d -a
317.Pp
318Fetch a package for a different
319.Fx
320version, along with all its dependencies:
321.Dl # pkg -o ABI=FreeBSD:15:amd64 -o IGNORE_OSVERSION=yes fetch -o destdir -d perl
322.Sh SEE ALSO
323.Xr ports 7 ,
324.Xr pkg 8
325.Sh HISTORY
326The
327.Nm
328command first appeared in
329.Fx 9.1 .
330It became the default package tool in
331.Fx 10.0 ,
332replacing the
333pkg_install suite of tools
334.Xr pkg_add 1 ,
335.Xr pkg_info 1 and
336.Xr pkg_create 1 .
337