Hack 84 Navigate the Ports System

figs/beginner.gif figs/hack84.gif

Use built-in commands to keep abreast of the FreeBSD ports collection.

What first attracted me to FreeBSD and what has definitely kept my attention since is the ports collection. Over 10,000 applications are a mere make install clean away. For a software junkie like myself, it is indeed Nerdvana to no longer scour the Internet for software or fight my way through dependency hell just to convince an application to install.

Admittedly, it's easy to get lost in a sea of ports. How do you choose which application best suits your needs? How do you keep track of which ports have been installed on your system? How do you make sure you don't inadvertently delete a dependency? Read on to see how to get the most out of the built-in utilities for managing ports.

8.9.1 Finding the Right Port

You know you want to install some software to add functionality to your system. Wouldn't it be great if you could generate a list of all the ports that are available for your specific need? Well, you can, and it's almost too easy with the built-in port search facility. In this example, I'll look for ports dealing with VPN software:

% cd /usr/ports % make search key=vpn | more Port:        poptop-1.1.4.b4_2 Path:        /usr/ports/net/poptop Info:        Windows 9x compatible PPTP (VPN) server Maint:        ports@FreeBSD.org Index:        net B-deps:        expat-1.95.6_1 gettext-0.12.1 gmake-3.80_1 libiconv-1.9.1_3 R-deps: <snip>

I snipped the results for brevity as this command gives the details of each port associated with VPNs. The format of the output is quite useful, as it gives the name of the port itself, its location in the ports tree, a brief description, the address of the maintainer, as well as the build and run dependencies.

If you're only interested in seeing how many ports are available, pipe the results to grep instead of more:

% make search key=vpn | grep Port Port:        poptop-1.1.4.b4_2 Port:        pptpclient-1.3.1 Port:        ike-scan-1.2 Port:        openvpn-1.5.0 Port:        tinc-1.0.2 Port:        vpnd-1.1.0

Perhaps you'd prefer to know their locations:

% make search key=vpn | grep Path Path:        /usr/ports/net/poptop Path:        /usr/ports/net/pptpclient Path:        /usr/ports/security/ike-scan Path:        /usr/ports/security/openvpn Path:        /usr/ports/security/tinc Path:        /usr/ports/security/vpnd

What if you already know the name of the port you want to install but aren't sure what versions are available? Use search name= instead. For example, this command will search for all ports with netscape in their names:

% make search name=netscape | grep Port Port:        pt_BR-netscape7-7.02 Port:        netscape-remote-1.0_1 Port:        netscape-wrapper-2000.07.07 Port:        netscape-communicator-4.78 Port:        netscape-navigator-4.78 Port:        linux-netscape-communicator-4.8 Port:        linux-netscape-navigator-4.8 Port:        netscape7-7.1

If you find the search facility useful, it is a good idea to update your ports index periodically. Become the superuser and issue the following command (it may take a while, so don't execute it if you're in a hurry):

# cd /usr/ports # make index

Finally, if you really want to fine-tune your search results, spend a few moments reading the examples in /usr/ports/Tools/scripts/README.portsearch.

8.9.2 Dealing with Installed Ports

You've spent a few months installing software and trying out new applications. How do you keep track of all of that software and all of those dependencies? pkg_info is your friend.

My favorite pkg_info switch is definitely -x. (There's not really a mnemonic for this switch; I tend to think of it as "give me version x.") If I stack it with any other switch, I don't need to know the full name (including the complete version number) of a port. For example:

% pkg_info -xc lynx

will show the one-line comment (-c) of every application that starts with lynx, regardless of the version number. Besides saving memory cells for other purposes, it's an excellent way to find out if you have more than one version of lynx installed.

After installing a port, it's useful to see if there were any messages, as these often contain configuration instructions:

% pkg_info -xD xmms Information for xmms-esound-1.2.8_2: Install notice: Xmms supports Gzipped and uncompressed skins.  If you would like to use Zip format skins you will need to ensure archivers/unzip is installed.

How many times have you installed a port and had no clue regarding the name of the executable, much less the names and locations of any configuration files or documentation? Thank goodness for -L, the file-listing flag:

% pkg_info -xL lynx | more Information for lynx- Files: /usr/local/man/man1/lynx.1.gz /usr/local/bin/lynx /usr/local/etc/lynx.cfg.default /usr/local/share/doc/lynx/CHANGES <snip>

Depending upon the application, the listing may be quite long. A judicious pipe to grep bin, grep man, or grep doc may better suit your purposes.

8.9.3 Checking Dependencies Before Uninstalling

Before uninstalling an application, it is always a good idea to see if any other packages require that application as a dependency. For example, you've typed pkg_info | more and see the application ORBit-0.5.17. You think to yourself, "I don't remember installing, or even ever using, this application. Where did it come from? Maybe I should just get rid of it." This command will clear up your mini-mystery:

% pkg_info -xR ORBit Information for ORBit-0.5.17_1: Required by: bonobo-1.0.22 flashplugin-mozilla-0.4.10_4 <snip>

Since the snipped output took up most of a page, it looks like this application is useful after all. Don't worry; if you did try to uninstall that application, pkg_delete would refuse since it is required by those other applications. However, it is always nice to be aware of these things ahead of time.

If you really do want to force the uninstall of an application, use -F (force) with pkg_delete.

8.9.4 Checking the Disk Space Your Ports Use

What happens if you go a little install-crazy and end up with more applications than disk space? Use the -s (size) switch to determine how much space an application uses. Send the output either to a pager:

% pkg_info -as | more

or to a file that you can read at your leisure:

% pkg_info -as > sizes

You'll then have an idea of which applications are using the most space so that you can decide which ones are worth uninstalling. Remember, you also have the comment and dependencies switches to help you decide.

Yet another way to find out what software you have installed is to use pkg_version:

% pkg_version | more

This will list each installed application, in alphabetical order. You'll note that each application is followed by one of the three symbols in Table 8-1.

Table 8-1. pkg_version symbols




The application is up-to-date.


There is a newer version of the application available.


Your index may be out-of-date.

So, to determine which applications require upgrading:

% pkg_version -l "<"

Note that you need to place quotes around the less-than sign or your shell will complain about a missing name for your redirect. If you don't receive any output, congratulations! All of your applications are up-to-date. If you do receive some output, you know which applications require an upgrade.

Alternately, this command will show all applications that are out-of-date:

% pkg_version -L "="

See man pkg_version if you didn't catch the difference between -l and -L.

If you prefer a more verbose output than =, >, or <, try this command:

% pkg_version -v | more

If for some reason you're not using cvsup to keep your ports tree up-to-date, you can still check your installed ports against the latest ports tree:

% pkg_version -v ftp://ftp.freebsd.org/pub/FreeBSD/branches/-current \     /ports/INDEX | more

8.9.5 See Also

  • /usr/ports/README

  • man pkg_info

  • man pkg_delete

  • man pkg_version

  • man ports

  • The Installing Packages and Ports section of the FreeBSD Handbook (http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports.html)

BSD Hacks
BSD Hacks
ISBN: 0596006799
EAN: 2147483647
Year: 2006
Pages: 160
Authors: Lavigne

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net