FreeBSD package management

(This information is now available in our wiki in table format.)

The following is a short of cheat sheet I’ve put together for FreeBSD management.  All this information is available in the FreeBSD manual, but I prefer the “to the point” format of a cheat sheet.

Note that along with the individual package management commands, the sysinstall(8) utility can be used to install, delete, and list available and installed packages on a running system.

Packages page in the Freebsd manual:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/packages-using.html

The sysinstall utility can be invoked on a running system to install, delete, and list available and installed packages.

Finding a packages:

Websites:

– http://www.FreeBSD.org/ports
– http://www.FreshPorts.org

In FreeBSD (both make use of the ports system to find packages, dont’t feel you have to install the port):

whereis command

# whereis lsof
lsof: /usr/ports/sysutils/lsof

make command

# cd /usr/ports
# make search name=lsof
Port:   lsof-4.56.4
Path:   /usr/ports/sysutils/lsof
Info:   Lists information about open files (similar to fstat(1))
Maint:  obrien@FreeBSD.org
Index:  sysutils
B-deps:
R-deps:

Port gives you the package/port name.
Path tell’s you where to find the package/port.

The  example, the lsof package can be found in:
ftp://ftp.ca.freebsd.org/pub/FreeBSD/releases/i386/7.2-RELEASE/packages/sysutils/

Package management

Adding a packages from a local file

# pkg_add <package-file>

Adding a package from a remote server

# pkg_add -r <package-file>

Two environment variables affect where pkg_add will pull it’s packages from
when the -r option is used.

$PACKAGEROOT specifies an alternate server for pkg_add to fetch from.
Example: “ftp://ftp3.FreeBSD.org”

$PACKAGESITE specifies an alternate server with a full path for pkg_add to fetch from.
Thus it should be a complete URL to the remote package file(s).
Example: ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-5-stable/Latest/

Listing packages

pkg_info <options> <file|package name>
When run with no options, lists installed packages

– pkg_version:  Compares version of installed package to the version in the ports directory.

Removing  packages

pkg_delete <package-name>
Example:  pkg_delete xchat-1.7.1

pkg_add: Specifying a mirror server

Pretty simple, just set the PACKAGEROOT environment variable.  For example:

export PACKAGEROOT=ftp://ftp3.ca.freebsd.org

There are other variables you can set, but they require more specific paths.  What I like about PACKAGEROOT is it lets you specify your mirror and let pkg_add figure out the rest.

A list of FreeBSD mirrors can be found at http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/mirrors-ftp.html.

Update: On OpenBSD a similar variable is used: PKG_PATH.