Web www.freebsdmadeeasy.com
Main Menu

Using the Ports Collection

One of the most useful and unique features of FreeBSD compared to most Linux distros is the Ports Collection. It can be found under /usr/ports and contains the Makefiles for a vast amount of software.

Getting the ports collection

If you did not choose to install the ports collection during the FreeBSD installation then you will need to get it through Cvsup.

The ports collection can also be accessed by ftp using

# /stand/sysinstall

Once you are in the FreeBSD configuration tool go to Configure and then Packages. Here you will want to choose FTP. Select the packages you wish to install and go to Install at the end and FreeBSD will use the pkg_add tool on each one to quickly add it.

Finding a Port

With so many ports it can be hard to find the one you are looking for. The easiest way to find a port is to use the ports directory on the FreeBSD website.

To search locally on your machine you can use the locate command if you know a word in the name of the package

# locate ‹package› | grep distinfo

The "grep distinfo" filters out other files in the port directory so each port that comes up is only shown once.

Files in the port directories

- This is the main file that tells where the files for the port are located and the options to build with. If you wish to install the port with certain options it is a good idea to look through this file and see what is available.

- Gives the version number of the package

- This is displayed after the port is installed giving information on how to finish setting it up, or security warnings. If you get the port installed and can't figure out how to start it, or where the config files are you should look back at the message.

- A list of files in the package.

Installing a port

To install a port change to its directory and do a "make install". For example, if we were to install the dns server bind9 it would look like this

# cd /usr/ports/dns/bind9
# make install

To delete the tar file that was downloaded to install bind9 once the install was complete simply append the command "distclean" after install like this

# cd /usr/ports/dns/bind9
# make install distclean

To clean out compiled files from the make use "make clean" in the port's directory

# make clean

If you wished to uninstall bind9 you could do so with the following

# cd /usr/ports/dns/bind9
# make deinstall

Many ports give a menu during the install asking you to choose certain options. If you wish to skip these menus "all" may be appended after "make install" to install the port more forcefully

# make install all

Removing a saved configuration

Ports that give a menu with installation options after starting the make save your choices and this saved config needs to be manually removed if you want to rebuild the port later and want different options. To delete a saved config go to port's directory and run

# make rmconfig

Viewing installed packages and removing them

A list of all installed packages on the machine can be viewed with "pkg_info"

# pkg_info

Deleting a package can be done with "pkg_delete"

# pkg_delete -f autoconf-2.53_3

The -f flag forces the package to be deinstalled even if other packages depend on it.

Cleaning up the ports

FreeBSD saves all files downloaded to install the ports to /usr/ports/distfiles

# rm -r /usr/ports/distfiles/*

Removes all of these files, but not the files created during the build. To get rid of these you must run

# portsclean -CD

The -CD flags will remove all files in the work directories within the ports tree and any unreferenced distfiles.

Upgrading a port

A port can be upgraded with the port /usr/ports/sysutils/portupgrade

# portupgrade autoconf-2.53_3