This page was last modified: July 24 2008 00:54:01   
Too Cool for Internet Explorer

The ports collection

When I started to learn about FreeBSD, one of my biggest fears was the process of installing new software. I was absolutely sure, that it would not be that easy. But it is! The ports collection does all the work ... you only have to write a few extremely simple commands.

But what exactly is the ports collection? Thousands of applications has been developed for use on FreeBSD. The ports collection holds information about all these applications. The information contains everything your system needs to install an application. So instead of doing everything yourself (downloading, unpacking, patching, compiling, installing) you just run a few commands.

In short (Quote from freebsd.org "Overview of Software Installation" ): A FreeBSD port for an application is a collection of files designed to automate the process of compiling an application from source code.

You'll soon come across the term "Package". A package is a precompiled port, so packages are preferable when installing large applications which might take ours for your computer to compile.

Getting the ports collection

I used an application called CVSup to get the ports collection. If you don't have that application, you need to install it. It is of course possible to install CVSup from the ports collection, but if you don't have the ports collection yet, use pkg_add to fetch and install it.:

pkg_add -r cvsup-without-gui

pkg_add installs an application from a package.

The -r option tells the system to fetch the package from a remote location. The last option csvup-without-gui is the name of the package I want.

pkg_add -r will by default fetch the package from ftp://ftp.FreeBSD.org unless you've changed the value of the environment variable PACKAGEROOT.

Now I have the tool for getting the ports collection ... The next step is to make a copy of CVSup's configuration file and do one minor change.

First I make a copy...

cp usr/share/examples/cvsup/ports-supfile /usr/local/etc

Then open the copy ...

vi /usr/local/etc/ports-supfile

Change the url to fetch from, to a location near you ... since I live in Denmark I choose a Danish server. Just locate this line: *default host=CHANGE_THIS.FreeBSD.org and change it. I changed it to *default host=cvsup.dk.freebsd.org. If you don't have a clue of which mirror to use, take at look at CVSup mirror sites listed in the FreeBSD Handbook

The only thing left to do is telling CVSup to go to work, then sit back and wait...

cvsup /usr/local/etc/ports-supfile

Installing applications from ports

When CVSup is finished you'll find the ports collection in /usr/ports. It is hierarchically organized. If for example you want to find and install the shell bash2, you do the following:

cd /usr/ports/shells/bash2/
make
make install
make clean
make distclean

In the first line the comman "make" fetches the necessary files and compiles them. "make install" installs the application. "make clean" and "make distclean" cleans up work/ and distfiles/ directories.

It is possible to do it all in one stroke...

cd /usr/ports/shells/bash2/
make install clean distclean

You should of course always get som background information of the application before you install. Some ports take arguments to the make command, as for example the cyrus-sasl package:

/usr/ports/security/cyrus-sasl2
make WITH_MYSQL=yes install clean

The WITH_MYSQL=yes option specifies that cyrus-sasl2 is installed with support for MySQL.

These days, most packages with options will display a nice menu where default options are preselected. You can add or change the selection and then proceed with the installation. You can also take a look at the file called 'Makefile'. This file is present in the root of every port, and it will also reveal any available options.

It is my experience that the best way to install is by running make, and then make install clean:

/usr/ports/security/cyrus-sasl2
make WITH_MYSQL=yes
make install clean

It is also always a good idea to check any dependencies the application might have. You could get into trouble if some dependencies have already been installed with another version than expected.

If you need to reinstall a package you can do..

make clean
make deinstall
make config
make reinstall

The 'make config' command lets you re-configure the installation, in case you want to use options different from the prior installation. 'make rmconfig' will delete the configuration entirely.

Don't forget to keep your packages up-to-date (see this article).

Deleting installed applications

The command pkg_delete is used to remove applications installed from ports. Only one argument is mandatory, that is the packagename. But it takes several other very usefull arguments - I've descriped some of them here:

-n
With this argument you can run a test deletion. It will not do anything exept from reporting what will be done, if the applications was actually deleted
-a
Be carefull - this will delete all currently installed packages, unconditionally.
-d
The d argument will remove any folders which is left empty after the deletion of the application, even if the folders was not created by the specified package at installation time.
-r
In addition to the specified package, this will delete all packages that depend on this package as well

Here's an example

pkg_delete -rd packagename

The above will delete <packagename> and any other applications that depends on it. All emptied folders will also be removed from the system

Getting information about installed packages

 pkg_info -o packagename   will show you the path to the ports collection from where the package was installed

 pkg_info -R packagename   will show you the names of installed packages depending on <packagename>

 pkg_info -r packagename   will show you the names of installed packages that <packagename> is depending on