The following sections provide basic instructions on using the ports collection toinstall or remove programs from your system.
Before you can install ports, you must first obtain the ports collection--which isessentially a set of Makefiles, patches, and description filesplaced in /usr/ports.
When installing your FreeBSD system, sysinstall asked ifyou would like to install the ports collection. If you chose no, you can follow theseinstructions to obtain the ports collection:
This method involves using sysinstall again to manuallyinstall the ports collection.
The alternative method to obtain and keep your ports collection up to date is by usingCVSup. Look at the ports CVSupfile, /usr/share/examples/cvsup/ports-supfile. See
This is a quick method for getting the ports collection using
The first thing that should be explained when it comes to the ports collection is whatis actually meant by a ``skeleton''. In a nutshell, a port skeleton is a minimal set offiles that tell your FreeBSD system how to cleanly compile and install a program. Eachport skeleton includes:
Some ports have other files, such as pkg-message. The portssystem uses these files to handle special situations. If you want more details on thesefiles, and on ports in general, check out the FreeBSD Porter's Handbook.
Now that you have enough background information to know what the ports collection isused for, you are ready to install your first port. There are two ways this can be done,and each is explained below.
Before we get into that, however, you will need to choose a port to install. There area few ways to do this, with the easiest method being the ports listing on the FreeBSD website. You can browse through the ports listed there or use the search function on thesite. Each port also includes a description so you can read a bit about each port beforedeciding to install it.
Another method is to use the
# whereis lsoflsof: /usr/ports/sysutils/lsof
This tells us that lsof (a system utility) can be found inthe /usr/ports/sysutils/lsof directory.
Yet another way to find a particular port is by using the ports collection's built-insearch mechanism. To use the search feature, you will need to be in the
# cd /usr/ports# make search name=lsofPort: lsof-4.56.4Path: /usr/ports/sysutils/lsofInfo: Lists information about open files (similar to fstat(1))Maint: obrien@FreeBSD.orgIndex: sysutilsB-deps: R-deps:
The part of the output you want to pay particular attention to is the ``Path:'' line,since that tells you where to find the port. The other information provided is not neededin order to install the port, so it will not be covered here.
For more in-depth searching you can also use make search key=
In both of these cases, the search string is case-insensitive. Searching for ``LSOF''will yield the same results as searching for ``lsof''.
Now that you have found a port you would like to install, you are ready to do theactual installation. The port includes instructions on how to build source code, but doesnot include the actual source code. You can get the source code from a CD-ROM or from theInternet. Source code is distributed in whatever manner the software author desires.Frequently this is a tarred and gzipped file, but it might be compressed with some othertool or even uncompressed. The program source code, whatever form it comes in, is calleda ``distfile''. You can get the distfile from a CD-ROM or from the Internet.
The FreeBSD Project's official CD-ROM images no longer include distfiles. They take upa lot of room that is better used for precompiled packages. CD-ROM products such as theFreeBSD PowerPak do include distfiles, and you can order these sets from a vendor such asthe FreeBSD Mall. This sectionassumes you have such a FreeBSD CD-ROM set.
Place your FreeBSD CD-ROM in the drive. Mount it on /cdrom.(If you use a different mount point, the install will not work.) To begin, change to thedirectory for the port you want to install:
# cd /usr/ports/sysutils/lsof
Once inside the lsof directory, you will see the portskeleton. The next step is to compile, or ``build'', the port. This is done by simplytyping make at the prompt. Once you have done so, you should seesomething like this:
# make>> lsof_4.57D.freebsd.tar.gz doesn't seem to exist in /usr/ports/distfiles/.>> Attempting to fetch from file:/cdrom/ports/distfiles/.===> Extracting for lsof-4.57...[extraction output snipped]...>> Checksum OK for lsof_4.57D.freebsd.tar.gz.===> Patching for lsof-4.57===> Applying FreeBSD patches for lsof-4.57===> Configuring for lsof-4.57...[configure output snipped]...===> Building for lsof-4.57...[compilation output snipped]...#
Notice that once the compile is complete you are returned to your prompt. The nextstep is to install the port. In order to install it, you simply need to tack one wordonto the make command, and that word is
# make install===> Installing for lsof-4.57...[installation output snipped]...===> Generating temporary packing list===> Compressing manual pages for lsof-4.57===> Registering installation for lsof-4.57===> SECURITY NOTE: This port has installed the following binaries which execute with increased privileges.#
Once you are returned to your prompt, you should be able to run the application youjust installed. Since lsof is a program that runs with increasedprivileges, a security warning is shown. During the building and installation of ports,you should take heed of any other warnings that may appear.
As with the last section, this section makes an assumption that you have a workingInternet connection. If you do not, you will need to perform the
Installing a port from the Internet is done exactly the same way as it would be if youwere installing from a CD-ROM. The only difference between the two is that the distfileis downloaded from the Internet instead of read from the CD-ROM.
The steps involved are identical:
# make install>> lsof_4.57D.freebsd.tar.gz doesn't seem to exist in /usr/ports/distfiles/.>> Attempting to fetch from ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/.Receiving lsof_4.57D.freebsd.tar.gz (439860 bytes): 100%439860 bytes transferred in 18.0 seconds (23.90 kBps)===> Extracting for lsof-4.57...[extraction output snipped]...>> Checksum OK for lsof_4.57D.freebsd.tar.gz.===> Patching for lsof-4.57===> Applying FreeBSD patches for lsof-4.57===> Configuring for lsof-4.57...[configure output snipped]...===> Building for lsof-4.57...[compilation output snipped]...===> Installing for lsof-4.57...[installation output snipped]...===> Generating temporary packing list===> Compressing manual pages for lsof-4.57===> Registering installation for lsof-4.57===> SECURITY NOTE: This port has installed the following binaries which execute with increased privileges.#
As you can see, the only difference is the line that tells you where the system isfetching the port distfile from.
The ports system uses
For users which cannot be connected all the time, the make
In some rare cases, users may need to acquire the tarballs from a site other than theMASTER_SITES (the location where files are downloaded from). Youcan override the MASTER_SITES option with the followingcommand:
# cd /usr/ports/
In this example we change the MASTER_SITES option to
Sometimes it is useful (or mandatory) to use a different distfiles and portsdirectory. The PORTSDIR and PREFIXvariables can override the default directories. For example:
will compile the port in /usr/home/example/ports and installeverything under /usr/local.
will compile it in /usr/ports and install it in
And of course,
will combine the two (it is too long to completely write on this page, but it shouldgive you the general idea).
Alternatively, these variables can also be set as part of your environment. Read themanual page for your shell for instructions on doing so.
Some ports that use imake (a part of the X Window System) donot work well with PREFIX, and will insist on installing under/usr/X11R6. Similarly, some Perl ports ignore
Now that you know how to install ports, you are probably wondering how to remove them,just in case you install one and later on decide that you installed the wrong port. Wewill remove our previous example (which was lsof for those ofyou not paying attention). As with installing ports, the first thing you must do ischange to the port directory, /usr/ports/sysutils/lsof. Afteryou change directories, you are ready to uninstall lsof. This isdone with the make deinstall command:
# cd /usr/ports/sysutils/lsof# make deinstall===> Deinstalling for lsof-4.57
That was easy enough. You have removed lsof from your system.If you would like to reinstall it, you can do so by running makereinstall from the /usr/ports/sysutils/lsof directory.
The make deinstall and makereinstall sequence does not work once you have run makeclean. If you want to deinstall a port after cleaning, use
Using the ports collection can defiantly eat up your disk space. For this reason youshould always remember to clean up the work directories using the
Some users choose to limit the port categories by placing an entry in the
Keeping your ports up to date can be a tedious job. For instance, to upgrade a portyou would go to the ports directory, build the port, deinstall the old port, install thenew port, and then clean up after the build. Imagine doing that for five ports, tediousright? This was a large problem for system administrators to deal with, and now we haveutilities which do this for us. For instance the
Now create a database with the pkgdb -F command. This willread the list of installed ports and create a database file in the
If you want to upgrade only a certain application, not the complete database, use
Other utilities exist which will do this, check out the
This, and other documents, can be downloaded from
For questions about FreeBSD, read the