In addition to the traditional UNIX® method of installing software (download source, extract, edit source code, and compile), FreeBSD offers two other methods for installing applications: packages and ports. A complete list of of all available ports and packages can be found here.
Packages are pre-compiled applications, the FreeBSD equivalents of .deb files on Debian/Ubuntu based systems and .rpm files on Red Hat/Fedora based systems. Packages are installed using pkg_add(1). For example, the following command installs Apache 2.2:
# pkg_add /tmp/apache-2.2.6_2.tbz
Using the -r
switch will tell pkg_add(1) to
automatically fetch a package and install it, as well as any dependencies:
# pkg_add -r apache22 Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/Latest/apache22.tbz... Done. Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/All/expat-2.0.0_1.tbz... Done. Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/All/perl-5.8.8_1.tbz... Done. [snip] To run apache www server from startup, add apache22_enable="YES" in your /etc/rc.conf. Extra options can be found in startup script.
Note: If you are running a release version of FreeBSD (6.2, 6.3, 7.0, etc., generally installed from CD-ROM) pkg_add -r will download packages built for that specific release. These packages may not be the most up-to-date version of the application. You can use the PACKAGESITE variable to override this default behavior. For example, set PACKAGESITE to ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6-stable/Latest/ to download the most recent packages built for the 6.X series.
You can read more about the FreeBSD versions in the article Choosing the FreeBSD Version That Is Right For You.
For more information on packages please refer to section 4.4 of the FreeBSD Handbook: Using the Packages System.
FreeBSD's second method for installing applications is the Ports Collection. The Ports Collection is a framework of Makefiles and patches specifically customized for installing various software applications from source on FreeBSD. When installing a port the system will fetch the source code, apply any required patches, compile the code, and install the application (and do the same for any dependencies).
The Ports Collection, sometimes referred to as the ports tree, can be found in /usr/ports. That is assuming the Ports Collection was installed during the FreeBSD installation process. If the Ports Collection has not been installed it can be added from the installation discs using sysinstall(8), or pulled from the FreeBSD servers using csup(1) or portsnap(8). Detailed instructions for installing the Ports Collection can be found in section 4.5.1 of the handbook.
Installing a port is as simple (generally) as changing in to the port's directory and starting the build process. The following example installs Apache 2.2 from the Ports Collection:
# cd /usr/ports/www/apache22 # make install clean
A major benefit of using ports to install software is the ability to customize the installation options. For example, when installing Apache 2.2 from ports you can enable mod_ldap by setting the WITH_LDAP make(1) variable:
# cd /usr/ports/www/apache22 # make WITH_LDAP="YES" install clean
Please see section 4.5 of the FreeBSD Handbook, Using the Ports Collection, for more information about the Ports Collection.
Packages are just pre-compiled ports, so it is really a matter of installing from source (ports) versus installing from binary packages. Each method has its own benefits:
Packages (binary)
Faster installation (compiling large applications can take quite a while).
You do not need to understand how to compile software.
No need to install compilers on your system.
Ports (source)
Ability to customize installation options. (Packages are normally built with standard options. With ports you can customize various options, such as building additional modules or changing the default path.)
You can apply your own patches if you are so inclined.
If you do not have any special requirements, packages will probably suit your situation just fine. If you may ever need to customize, ports are the way to go. (And remember, if you need to customize but prefer packages, you can build a custom package from ports using make package and then copy the package to other servers.)
This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.
For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.