FreeBSD Operating System

The Ports Collection

Разбить на страницы
Показывать лекцию целиком

The Internet is full of free software that is normally distributed in source form. That can be a problem in it self: the way from the source archive that you get free from the Internet to the finished, installed, running program on your machine—normally called porting, — can be a long and frustrating one. See my book Porting UNIX Software, for more details of the porting process.

To get a software package up and running on your system, you need to go through most of these steps:

  • Get the source files on your machine. They are usually contained in an archive, a file containing a number of other files. Archives used for the ports collection are generally gzipped tar, files, packaged with tar, and compressed with gzip, but other formats are also possible. What ever the format, you'll typically use ftp, to get them to your machine.
  • Unpack the archive source tree, in this case using gunzip, and tar,
  • Configure the package. Most packages include shell scripts to do this. Configuration performs a threefold adaptation of the package:
  • It adapts it to the system hardware.
  • It adapts it to the software environment you're running (in this case, FreeBSD).
  • It adapts it to your personal preferences.
  • Build the package. For most packages, this involves compiling the source files and creating executable. The main tool for this purpose is make, which uses a set of rules, traditionally stored in a file called Makefile, to decide how to build the package. There is nearly always a Makefile, in the sources, but the Ports Collection includes a second one that controls the build at a higher level.
  • Install the package. This involves mainly copying the executable, configuration files and documentation created by a build to the correct place in the directory hierarchy.
  • Configure the installed software. This is similar in concept to package configuration, except that it occurs in the run-time environment. The package configuration may perform all the necessary configuration for you.
  • These are a lot of steps, and you'll often find they're laid through a minefield: one false move and everything blows up. To make porting and installing software easier, the FreeBSD team created a framework called the Ports Collection, which makes it trivial to perform these steps. It also provides a method of packaging and installing the resultant ported software, called packages, The CD-ROM edition of FreeBSD includes a large number of pre-built packages that can be installed directly.

    In this chapter, we'll consider the following points as they relate to the FreeBSD ports collection:

  • How to install a pre-compiled package. We'll look at this in the next section.
  • What the ports tree is, and how to compile and install (''build'') a package. We'll look at this on page 169.
  • How to create and submit a new port, on page 174.
  • How to install a package

    In FreeBSD parlance, a package is simply a special archive that contains those files (usually executable binary files) that are installed when you build and install a port. Effectively it's a snapshot of the port build process that we saw above, taken after step 4 has completed. Compared to the full-blown port, packages are much faster to install—it's usually a matter of seconds. On the other hand, they don't give you the choice of configuration that the complete port does. The distribution CD-ROMs contain a directory packages, with a large number of pre-compiled software packages. Alternatively, you can find FreeBSD packages on many servers on the Internet—check the online handbook for some places to look.

    To help maintain an overview, both ports and packages are divided into categories. They are stored in directories named after the category. See the file /usr/ports/INDEX, for a list. For example, emacs, under editors, is currently in the file packages/editors/emacs-21.2.tgz, though this name will change with updated versions of emacs. For, the latest version of the packages only, you'll find another copy without the extension in packages/Latest/emacs.tgz. To install it, you enter:

    pkg_add /cdrom/packages/Latest/emacs.tgz
    

    Alternatively, you can install packages from the sysinstall, final configuration menu shown in Figure 6-1.

    Building a port

    The more general way to install third-party software is with a port, The FreeBSD project uses the term port to describe the additional files needed to adapt a package to build under FreeBSD. It does not include the source code itself, though the CD-ROM distribution includes many code archives in the directory /ports/distfiles, spread over several of the CD-ROMs.

    Before you get started with the ports, you need to install the port information on your system. Normally this will be in /usr/ports. This directory tree is frequently called the Ports Tree. There are a number of ways to install them.

    Installing ports during system installation

    The simplest way to install the Ports Collection is when you install the system. When you choose the components to install, sysinstall, offers to install the Ports Collection for you as well.

    Installing ports from the first CD-ROM

    The file ports/ports.tgz, on the first CD-ROM is a tar, archive containing all the ports. If you didn't install it during system installation, use the following method to install the complete collection (about 200 MB). Make sure your CD-ROM is mounted (in this example on /cdrom), and enter:

    #  cd /usr
    #  tar xzvf /cdrom/ports/ports.tgz
    

    If you only want to extract a single package, say inn, which is in the categorynews, enter :

    #  cd /usr
    #  tar xzvf /cdrom/ports/ports.tgz ports/news/inn
    

    It takes a surprisingly long time to install the ports; although there isn't much data in the archive, there are about 250,000 files in it, and creating that many files takes a lot of disk I/O.

    Installing ports from the live file system CD-ROM

    Alternatively, the files are also on the live file system CD-ROM. This is not much of an advantage for installation, but you may find it convenient to browse through the source trees in the directory ports, on the CD-ROM. Let's assume you have found a directory /cdram/ports/graphics/hp scan, on the CD-ROM, and it is your current working directory. You can move the data across with the following:

    #  cd /cdram/ports/graphics
    #  mkdir -p /usr/ports/graphics
    #  tar cf - . | (cd /usr/ports/graphics; tar xvf -)
    

    Getting new ports

    What happens when a new version of a port comes out? For example, you've been using Emacs Version 20 forever, and now Version 21.2 becomes available? It's brand new, so it's obviously not on your CD-ROM.

    One way to get the port is via ftp. This used to be quite convenient: you could download a tar ball directly and extract it locally. That is unfortunately no longer possible: currently you must download files a directory at a time. If you're following the Ports Collection at all closely, you should consider using cvsup, which can keep your sources up to date automatically. See Chapter 31, page 585, for more details.

    All ports are kept in subdirectories of the URL ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/. This directory has the following contents:

    drwxr-xr-x    6  1006  1006     512  Jun   8  13:18  alpha
    drwxr-xr-x  209  1006  1006  401408  May  28  14:08  dist files
    drwxr-xr-x    6  1006  1006    1536  May  28  17:53  i386
    drwxr-xr-x    3  1006  1006     512  Apr   6  13:45  ia64
    drwxr-xr-x   83  1006  1006    3072  May  20  15:35  local-dist files
    lrwxrwxrwx    1  root  wheel     13  Jun   1   2001  packages -> i386/packages
    lrwxrwxrwx    1  root  wheel     24  Jun   1   2001  ports -../FreeBSD-current/ports
    lrwxrwxrwx    1  root  wheel      5  Jun   1   2001  ports-current -> ports
    lrwxrwxrwx    1  root  wheel      5  Jun   1   2001  ports-stable -> ports
    drwxr-xr-x    4  1006  1006     512  Apr   9  10:37  sparc64
    

    The directories alpha, i386, ia64, and sparc64, contain packages (not ports) for the corresponding architecture. dist files contains a large number of the original sources for the third-party packages; it's intended as a ''last resort'' location if you can't find them at other locations.

    The directory local-dist files, is used by people working on the Ports Collection; you don't normally need anything from these directories. The important directories for you are ports, ports-current, and ports-stable. Currently these are really all the same directory, but things may not remain like that.

    Getting back to your emacs, port: you would find it in the directory /pub/Free-BSD/ports/ports/editors/ . Note the final / in that directory name: if you leave it out, ftp prints an error message and exits. Here's what might happen:

    $ ftp ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/ports/editors/
    Connected to ftp.beastie.tdk.net.
    220 ftp.beastie.tdk.net FTP server (Version 6.00LS) ready.
    331 Guest login ok, send your email address as password.
    230- The FreeBSD mirror at Tele Danmark Internet.
    ...much blurb omitted
    250 CWD command successful.
    250 CWD command successful.
    ftp> ls
    229 Entering Extended Passive Mode (|||55649|)
    150 Opening ASCII mode data connection for '/bin/ls'.
    total 704
    
    drwxr-xr-x  3  1006  1006  512  May  20  10:07  emacs
    drwxr-xr-x  4  1006  1006  512  May  20  10:08  emacs20
    drwxr-xr-x  4  1006  1006  512  May  20  10:08  emacs20-dl
    drwxr-xr-x  4  1006  1006  512  May  20  10:08  emacs20-mule-devel
    drwxr-xr-x  3  1006  1006  512  May  20  10:08  emacs21
    drwxr-xr-x  2  1006  1006  512  May  20  10:08  eshell-emacs20
    

    This shows that your files will be in the directory emacs21. You can get them with the ftp mget, command:

    ftp> mget emacs21
    mget emacs21/files [anpqy?]? a           answer a for all files
    Prompting off for duration of mget.
    ftp: local: emacs21/files: No such file or directory
    ftp: local: emacs21/Makefile: No such file or directory
    (etc)
    

    This happens because you need to create the destination directory manually. Try again:

    ftp> !mkdir emacs21                      create the local directory
    ftp> mget emacs21
    mget emacs21/files [anpqy?]? a
    Prompting off for duration of mget.
    229 Entering Extended Passive Mode (|||57074|)
    550 emacs21/files: not a plain file.
    229 Entering Extended Passive Mode (|||57085|)
    150 Opening BINARY mode data connection for 'emacs21/Makefile'   (2185 bytes).
    100%  |*************************************|   2185   2.34 MB/s   00:00 ETA
    226 Transfer complete.
    (etc)
    

    You get one of these for each file transferred. But note the error message: not a plain file. emacs21/files, is a directory, so we need to get it separately:

    ftp> !mkdir emacs21/files
    ftp> mget emacs21/files
    mget emacs21/files/patch-lib-src:Makefile.in [anpqy?]? a
    Prompting off for duration of mget.
    229 Entering Extended Passive Mode (|||57258|)
    150 Opening BINARY mode data connection for 'emacs21/files/patch-lib-src: Make file. in '(908 bytes).
    100%  |*************************************|      908  1.64 MB/s       00:00 ETA
    226 Transfer complete.
    (etc)
    

    Note that the ftp command specifies the URL of the directory. It must have a trailing /, otherwise ftp will complain. This form is supported by FreeBSD ftp but many other ftp clients will require you to do it in two steps:

    # ftp ftp.EreeBSD.org
    Connected to ftp.beastie.tdk.net.
    (etc)
    ftp> cd /pub/FreeBSD/ports/ports/editors
    250 CWD command successful.
    

    What's in that port?

    One problem with the Ports Collection is the sheer number. It can be difficult just to find out what they're supposed to do. If you build all the ports, you'll be busy for weeks, and there's no way you could read all the documentation in one lifetime. Where can you get an overview? Here are some suggestions. In each case, you should have the directory /usr/ports, as your current working directory.

  • There's an index in /usr/ports/INDEX. If you have updated the ports tree, you can make the index with the following commands:
    #  cd /usr/ports
    #  make index
    

    index, is the name of a target, the part of a rule that identifies it. It's usually either a file name or an abbreviation for an operation to perform. We'll see a number of make, targets in the course of the book.

    The index is intended for use by other programs, so it's written as a single long line per package, with fields delimited by the vertical bar character (|). Here are two lines as an example, wrapped over three lines to fit on the page:

    mp3asm-0.1.3|/usr/ports/audio/mp3asm|/usr/local|MP3 frame level editor|/usr/port
    s/audio/mp3asm/pkg-descr|ports@FreeBSD.org|audio| autoconf213-2.13.000227_1||
    htt p://mp3asm.sourceforge.net/
    mp3blaster-3.0p8|/usr/ports/audio/mp3blaster|/usr/local|MP3 console ncurses-base
    dplayer|/usr/ports/audio/mp3blaster/pkg-descr|greid@FreeBSD.org|audio|||
    http:// www.stack.nl/~brama/mp3blaster.html
    

    You'll probably want to process it with other tools.

  • You can print the index with the following commands:
    #  cd /usr/ports
    #  make print-index | lpr
    

    Note that there are about 1,000 pages of output, which look like this:

    Port:    zip-2.3_1
    Path:    /usr/ports/archivers/zip
    Info:    Create/update ZIP files compatible with pkzip
    Maint:   ache@FreeBSD.org
    Index:   archivers
    B-deps:  unzip-5.50
    R-deps:
    
  • You can search for a specific keyword with the search target. For example, to find ports related to Emacs, you might enter:
    #  cd /usr/ports
    #  make search key=Emacs | less
    

    Pipe the output through less, it can be quite a lot.

  • You can build a series of nearly 10,000 html, pages like this:
    #  cd /usr/ports
    #  make readmes
    

    You can then browse them at the URL file:///usr/ports/README.html.

  • Getting the source archive

    You'll see from the above example that there are not many files in the port. Most of the files required to build the software are in the original source code archive (the "tar ball"), but that's not part of the port.

    There are a number of places from which you can get the sources. If you have a CD-ROM set, many of them are scattered over the CD-ROMs, in the directory /cdrom/ports/distfiles, on each CD-ROM. The Ports Collection Make files look for them in this directory (another good reason to mount your CD-ROM on /cdrom), and also in /usr/ports/distfiles.

    If you don't have the source tar ball, that's not a problem. Part of the function of the Ports Collection is to go out on the Net and get them for you. This is completely automatic: you just type make, and the build process gets the source archive for you and builds it. Of course, you must be connected to the Internet for this to work.

    If you mount your CD-ROM elsewhere (maybe because you have more than one CD-ROM drive, and so you have to mount the CD-ROM on, say, /cd4), the Make files will not find the distribution files and will try to load the files from the Internet. One way to solve this problem is to create a symbolic link from /cd4/ports/distfiles, to /usr/ports/distfiles. The trouble with this approach is that you will then no longer be able to load new distribution files into /usr/ports/distfiles, because it will be on CD-ROM. Instead, do:

    #  cd /cd4/ports/distfiles
    #  mkdir -p /usr/ports/distfiles       make sure you have a distfiles directory
    #  for i in *; do
    >  ln -s /cd4/ports/distfiles/$i /usr/ports/distfiles/$i
    >  done
    

    If you're using csh, or tcsh, enter:

    # cd /cd4/ports/distfiles
    # mkdir -p /usr/ports/distfiles       make sure you have a distfiles directory
    # foreach i (*)
    ?  ln -s /cd4/ports/distfiles/$i /usr/ports/distfiles/$i
    ? end
    

    This creates a symbolic link to each distribution file, but if the file for a specific port isn't there, the Ports Collection can fetch it and store it in the directory.

    Building the port

    Once you have the skeleton files for the port, the rest is simple. Just enter:

    #  cd /usr/ports/editors/emacs21
    #  make
    #  make install
    ====> To enable menubar fontset support, define WITH_MENUBAR_FONTSET
    >> emacs-21.2.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
    >> Attempting to fetch from ftp://ftp.gnu.org/gnu/emacs/.
    ===>   Extracting for emacs-21.2_1
    >> Checksum OK for emacs-21.2.tar.gz.
    ===>     emacs-21.2_1 depends on executable: gmake - found
    ===>     emacs-21.2_1 depends on executable: autoconf213 - not found
    ===>      Verifying install for autoconf213 in /usr/ports/devel/autoconf213
    ===>   Extracting for autoconf213-2.13.000227_2
    >> Checksum OK for autoconf-000227.tar.bz2.
    ===>     autoconf213-2.13.000227_2 depends on executable: gm4 - not found
    ===>      Verifying install for gm4 in /usr/ports/devel/m4
    ===>   Extracting for m4-1.4_1
    >> Checksum OK for m4-1.4.tar.gz.
    ===>   Patching for m4-1.4_1
    ===>   Applying FreeBSD patches for m4-1.4_1
    ===>   Configuring for m4-1.4_1
    creating cache ./config.cache
    checking for mawk... no
    (etc)
    

    It's a good idea to perform the make, step first: make install, does not always build the package.

    Port dependencies

    Sometimes, it's not enough to build a single port. Many ports depend on other ports. If you have the complete, up-to-date ports tree installed on your systcode, the Ports Collection will take care of this for you: it will check if the other port is installed, and if it isn't, it will install it for you. For example, tkdesk, depends on tk, tk depends on tcl. If you don't have any of them installed, and you try to build tkdesk, it will recursively install tk and tcl for you.

    Package documentation

    Once you have installed your port, you'll want to use it. In almost every case, that requires documentation. Most packages have documentation, but unfortunately it's not always obvious where it is. In some cases, the port doesn't install all the documentation.

    More generally, there are the following possibilities:

  • If the port includes man pages, they will be installed in /usr/X11R6/man, if the package is related to X, and /usr/local/man, if they are not. Typically installing the man pages is the last thing that happens during the installation, so you should see it on the screen. If not, or if you want to check, you can have a look at the package list:
    $ cd /var/db/pkg
    $ pkg_info -L emacs-21.2_l|grep /man/
    /usr/local/man/man1/ctags.1.gz
    /usr/local/man/man1/emacs.1.gz
    /usr/local/man/man1/etags.1.gz
    /usr/local/man/man1/gfdl.1.gz
    

    You don't need to change the directory to /var/db/pkg, but if you do, you can use file name completion to finish the name of the package. We use /man/ as the search string, and not simply man, because otherwise other files might match as well.

  • If the package includes GNU info pages, you can use the same method to look for them:
    $ pkg_info -L emacs-21.2_l|grep /info/
    /usr/local/info/ada-mode
    /usr/local/info/autotype
    /usr/local/info/ccmode
    /usr/local/info/cl (many more)
    

    This isn't normally necessary, though: if you're using GNU info, the index page will be updated to include the package.

  • If the package includes hard copy documentation, it may or may not be included in the port. The Emacs, documentation also includes a user's guide and a programmer's guide. The user's guide, all 640 pages of it, is in the directory man of the Emacs build directory, but it doesn't get built during installation. This is typical of most ports. In this case you'll have to build the documentation yourself.
  • Getting binary-only software

    A lot of software doesn't need to be ported. For example, if you want . But how, do you install it? Netscape's installation procedures are getting better, but they still leave something to be desired.

    The answer's simple: take the port! Although Netscape comes only in binary form, the port handles getting the correct version and installing it for you. Another advantage to using a port instead of installing the package manually is that the port installs the software as a FreeBSD package, which makes it much easier to remove the software later.

    This method can be used to install some other software as well, for example Star Office. The moral is simple: always check the Ports Collection before getting a software package from the Net.

    Maintaining ports

    Once you install a port, you might consider that to be the end of the story. That's seldom the case. For example:

  • You might need to replace a port with a newer version. How do you do it? We'll look at that below.
  • One day, you might find your disk fills up, so you go looking for old ports you don't use anymore. We'll look at some utility commands on page 178.
  • Upgrading ports

    From time to time, new versions of software will appear. There are a number of approaches to upgrading:

  • You can remove the old version of the port and install a new version. The trouble here is that removing the old version might remove any configuration files as well.
  • You can install a new version without removing the old version. The trouble here is that you end up with two entries in the packages database /var/db/pkg:
    $ pkg_info | grep emacs
    emacs-21.1_5  GNU editing macros
    emacs-21.2_1  GNU editing macros
    

    Clearly you don't need emacs-21.15 anymore. In fact, it's not complete anymore, because the program /usr/local/bin/emacs has been overwritten by the new version. But you can't remove it either: that would remove components of emacs-21.2_1, which you want to keep. On the other hand, if you don't remove it, you are left with nearly 50 MB of disk space used up in the directory /usr/local/share/emacs/21.1.

  • You can use portupgrade, a program that does some of the upgrading automatically. We'll look at this below.
  • Using portupgrade

    Portupgrade is—what else?—a port. Install it in the usual manner:

    # cd /usr/ports/sysutils/portupgrade
    # make install
    

    Before you can perform the upgrade, you should first back up /var/db/pkg, then build a ports database with pkgdb. A typical build might look like this:

    # cd /var/db
    # tar czvf db.pkg.tar.gz pkg/
    # pkgdb -F
    [Updating the pkgdb <format:bdb1_btree> in /var/db/pkg ... - 181 packages
    found (-5 +92)  (...)...............done]
    Checking the origin of AbiWord-1.0.3
    Checking the origin of ImageMagick-5.5.1.1
    Checking the origin of ORBit-0.5.17
    ...
    Checking the origin of xv-3.10a_3
    Checking the origin of zip-2.3_1
    Checking for origin duplicates
    Checking AbiWord-1.0.3
    Checking ImageMagick-5.5.1.1
    Stale dependency: ImageMagick-5.5.1.1 -> ghostscript-gnu-7.05_3:
    ghostscript-gnu-6.52_4 (score:64%) ?  ([y]es/[n]o/[a]ll)   [no] y
    Fixed. (-> ghostscript-gnu-6.52_4)
    Checking ORBit-0.5.17 Checking XFree86-4.2.0_1,1
    Checking bonobo-1.0.21_1
    Stale dependency: bonobo-1.0.21_1 -> ghostscript-gnu-7.05_3:
    ghostscript-gnu-6.52_4 ? ([y]es/[n]o/[a]ll)   [yes]        Enter pressed
    Fixed. (-> ghostscript-gnu-6.52_4)
    Checking cdrtools-1.11.a28
    ...
    Checking xv-3.10a_3
    Checking zip-2.3_1
    Regenerating +REQUIRED_BY files
    Checking for cyclic dependencies
    

    In this example, the port ghostscript-gnu-7.05 3 had been replaced by the earlier version ghostscript-gnu-6.52_4, since ghostscript Release 7 has some annoying bugs. The dialogue shows how pkgdb, recognized the discrepancy, and how it recovered from it.

    Now you can start the upgrade. To upgrade a specific port, simply specify its base name, without the version number. This example uses the -v, option to show additional information:

    # portupgrade -v bison
    ---> Upgrade of devel/bison started at: Mon, 04 Nov 2002 13:20:52 +1030
    ---> Upgrading 'bison-1.35_1' to 'bison-1.75' (devel/bison)
    ---> Build of devel/bison started at: Mon, 04 Nov 2002 13:20:52 +1030
    ... normal port build output
    ===> Registering installation for bison-1.75
    make clean issued by portupgrade
    ===> Cleaning for libiconv-1.8_2
    ===> Cleaning for gettext-0.11.5_1
    ...
    ---> Removing the temporary backup files
    ---> Installation of devel/bison ended at: Mon, 04 Nov 2002 13:23:00 +1030 (consume
    d00:00:06)
    ---> Removing the obsoleted dependencies
    ---> Cleaning out obsolete shared libraries
    ---> Upgrade of devel/bison ended at: Mon, 04 Nov 2002 13:23:01 +1030 (consumed 00:
    02:08)
    ---> Reporting the results ( + :succeeded / -:ignored / *:skipped / !:failed)
    +devel/bison (bison-1.35_1)
    

    If the port is already up to date, you'll see something like this:

    # portupgrade -v perl-5.8.0_3
    ** No need to upgrade 'perl-5.8.0_3'   (>= perl-5.8.0_3).  (specify -f to force)
    ---> Reporting the results ( + :succeeded / -:ignored / *:skipped / !:failed)
    -lang/perl5.8 (perl-5.8.0_3)
    

    To upgrade all ports, use the command:

    # portupgrade -a
    

    Controlling installed ports

    We've already seen the program pkg_add, when installing pre-compiled packages. There are a number of other pkg_ programs that can help you maintain installed ports, whether they have been installed by pkg_add, or by make install from the Ports Collection:

  • pkg_info, tells you which ports are installed. For example:
    $ pkg_info | less
    AbiWord-1.0.3        An open-source, cross-platform WYSIWYG word proces
    ImageMagick-5.5.1.1  Image processing tools (interactive optional--misc
    ORBit-0.5.17         High-performance CORBA ORB with support for the C
    XFree86-4.2.0_1,1    X11/XFree86 core distribution (complete, using min
    ... etc
    bash-2.05b.004       The GNU Bourne Again Shell
    bison-1.75           A parser generator from FSF, (mostly) compatible w
    bonobo-1.0.21_1      The component and compound document system for GNO
    cdrtools-1.11.a28    Cdrecord, mkisofs and several other programs to re
    ... etc
    elm-2.4ME+22         ELM Mail User Agent
    elm-2.4ME+32         ELM Mail User Agent
    

    Note that the last two entries in this example show that two versions of elm, are installed. This can't be right; it happens when you install a new version without removing the old version and without running portupgrade. We'll discuss this matter further below.

  • If you have the ports tree installed, you can use pkg_version, to check whether your ports are up to date. pkg_version, is a little cryptic in its output:
    AbiWord-gnome=
    ImageMagick<
    ORBit<
    Wingz=
    XFree86<
    x2x-1.28?
    The symbols to the right of the package names have the following meanings:
    =The installed version of the package is current.
    <The installed version of the package is older than the current version.
    >The installed version of the package is newer than the current version. This situation can arise with an out-of-date index file, or when testing new ports.
    ?The installed package does not appear in the index. This could be due to an out of date index o repackage that has not yet been committed.
    *There are multiple versions of a particular software package listed in the index file.
    !The installed package exists in the index but for some reason, pkgversion, was unable to compare the version number of the installed package with the corresponding entry in the index.
  • There are two ways to remove a port: if you've built it from source, and you're in the build directory, you can write:
    # make deinstall
    

    Alternatively, you can remove any installed package with pkg_delete. For example, the list above shows two versions of the elm, mail user agent. To remove the older one, we enter:

    #  pkg_delete elm-2.4ME+22
    File Vusr/local/man/manl/answer.l' doesn't really exist.
    Unable to completely remove file '/usr/local/man/manl/answer.1'
    File Vusr/local/man/manl/checkalias.l' doesn't really exist.
    Unable to completely remove file '/usr/local/man/manl/checkalias.l'
    ... etc
    Couldn't entirely delete package (perhaps the packing list is incorrectly specified?)
    

    In this case, it looks as if somebody has tried to remove the files before, so pkg_delete, couldn't do so.

    Another problem with pkg_delete, is that it might delete files of the same name that have been replaced by newer packages. After performing this operation, we try:

    $ elm
    bash: elm: command not found
    

    Oops! We tried to delete the old version, but we deleted at least part of the new version. Now we need to install it again.

    The moral of this story is that things aren't as simple as they might be. When you install a new version of a package, you may want to test it before you commit to using it all the time. You can't just go and delete the old version. One possibility would be to install the new package, and try it out. When you've finished testing, delete both, packages and re-install the one you want to keep.

  • Keeping track of updates

    The best way to find out about updates is to subscribe to the FreeBSD-ports mailing list. That way, you will get notification every time something changes. If you're tracking the ports tree with CVSup, you also get the updates to the ports tree automatically. Otherwise you will have to download the port. In either case, to update your installed port, just repeat the build.

    Submitting a new port

    The Ports Collection is constantly growing. Hardly a day goes by without a new port being added to the list. Maybe you want to submit the next one? If you have something interesting that isn't already in the Ports Collection, you can find instructions on how to prepare the port in the FreeBSD Porter's Handbook. The latest version is available on the FreeBSD web site, but you'll also find it on your system as /usr/share/doc/en/porters-handbook/index.html.

    Страницы:

    The Internet is full of free software that is normally distributed in source form. That can be a problem in it self: the way from the source archive that you get free from the Internet to the finished, installed, running program on your machine—normally called porting, — can be a long and frustrating one. See my book Porting UNIX Software, for more details of the porting process.

    To get a software package up and running on your system, you need to go through most of these steps:

  • Get the source files on your machine. They are usually contained in an archive, a file containing a number of other files. Archives used for the ports collection are generally gzipped tar, files, packaged with tar, and compressed with gzip, but other formats are also possible. What ever the format, you'll typically use ftp, to get them to your machine.
  • Unpack the archive source tree, in this case using gunzip, and tar,
  • Configure the package. Most packages include shell scripts to do this. Configuration performs a threefold adaptation of the package:
  • It adapts it to the system hardware.
  • It adapts it to the software environment you're running (in this case, FreeBSD).
  • It adapts it to your personal preferences.
  • Build the package. For most packages, this involves compiling the source files and creating executable. The main tool for this purpose is make, which uses a set of rules, traditionally stored in a file called Makefile, to decide how to build the package. There is nearly always a Makefile, in the sources, but the Ports Collection includes a second one that controls the build at a higher level.
  • Install the package. This involves mainly copying the executable, configuration files and documentation created by a build to the correct place in the directory hierarchy.
  • Configure the installed software. This is similar in concept to package configuration, except that it occurs in the run-time environment. The package configuration may perform all the necessary configuration for you.
  • These are a lot of steps, and you'll often find they're laid through a minefield: one false move and everything blows up. To make porting and installing software easier, the FreeBSD team created a framework called the Ports Collection, which makes it trivial to perform these steps. It also provides a method of packaging and installing the resultant ported software, called packages, The CD-ROM edition of FreeBSD includes a large number of pre-built packages that can be installed directly.

    In this chapter, we'll consider the following points as they relate to the FreeBSD ports collection:

  • How to install a pre-compiled package. We'll look at this in the next section.
  • What the ports tree is, and how to compile and install (''build'') a package. We'll look at this on page 169.
  • How to create and submit a new port, on page 174.
  • How to install a package

    In FreeBSD parlance, a package is simply a special archive that contains those files (usually executable binary files) that are installed when you build and install a port. Effectively it's a snapshot of the port build process that we saw above, taken after step 4 has completed. Compared to the full-blown port, packages are much faster to install—it's usually a matter of seconds. On the other hand, they don't give you the choice of configuration that the complete port does. The distribution CD-ROMs contain a directory packages, with a large number of pre-compiled software packages. Alternatively, you can find FreeBSD packages on many servers on the Internet—check the online handbook for some places to look.

    To help maintain an overview, both ports and packages are divided into categories. They are stored in directories named after the category. See the file /usr/ports/INDEX, for a list. For example, emacs, under editors, is currently in the file packages/editors/emacs-21.2.tgz, though this name will change with updated versions of emacs. For, the latest version of the packages only, you'll find another copy without the extension in packages/Latest/emacs.tgz. To install it, you enter:

    pkg_add /cdrom/packages/Latest/emacs.tgz
    

    Alternatively, you can install packages from the sysinstall, final configuration menu shown in Figure 6-1.

    Building a port

    The more general way to install third-party software is with a port, The FreeBSD project uses the term port to describe the additional files needed to adapt a package to build under FreeBSD. It does not include the source code itself, though the CD-ROM distribution includes many code archives in the directory /ports/distfiles, spread over several of the CD-ROMs.

    Before you get started with the ports, you need to install the port information on your system. Normally this will be in /usr/ports. This directory tree is frequently called the Ports Tree. There are a number of ways to install them.

    Installing ports during system installation

    The simplest way to install the Ports Collection is when you install the system. When you choose the components to install, sysinstall, offers to install the Ports Collection for you as well.

    Installing ports from the first CD-ROM

    The file ports/ports.tgz, on the first CD-ROM is a tar, archive containing all the ports. If you didn't install it during system installation, use the following method to install the complete collection (about 200 MB). Make sure your CD-ROM is mounted (in this example on /cdrom), and enter:

    #  cd /usr
    #  tar xzvf /cdrom/ports/ports.tgz
    

    If you only want to extract a single package, say inn, which is in the categorynews, enter :

    #  cd /usr
    #  tar xzvf /cdrom/ports/ports.tgz ports/news/inn
    

    It takes a surprisingly long time to install the ports; although there isn't much data in the archive, there are about 250,000 files in it, and creating that many files takes a lot of disk I/O.

    Installing ports from the live file system CD-ROM

    Alternatively, the files are also on the live file system CD-ROM. This is not much of an advantage for installation, but you may find it convenient to browse through the source trees in the directory ports, on the CD-ROM. Let's assume you have found a directory /cdram/ports/graphics/hp scan, on the CD-ROM, and it is your current working directory. You can move the data across with the following:

    #  cd /cdram/ports/graphics
    #  mkdir -p /usr/ports/graphics
    #  tar cf - . | (cd /usr/ports/graphics; tar xvf -)
    

    Getting new ports

    What happens when a new version of a port comes out? For example, you've been using Emacs Version 20 forever, and now Version 21.2 becomes available? It's brand new, so it's obviously not on your CD-ROM.

    One way to get the port is via ftp. This used to be quite convenient: you could download a tar ball directly and extract it locally. That is unfortunately no longer possible: currently you must download files a directory at a time. If you're following the Ports Collection at all closely, you should consider using cvsup, which can keep your sources up to date automatically. See Chapter 31, page 585, for more details.

    All ports are kept in subdirectories of the URL ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/. This directory has the following contents:

    drwxr-xr-x    6  1006  1006     512  Jun   8  13:18  alpha
    drwxr-xr-x  209  1006  1006  401408  May  28  14:08  dist files
    drwxr-xr-x    6  1006  1006    1536  May  28  17:53  i386
    drwxr-xr-x    3  1006  1006     512  Apr   6  13:45  ia64
    drwxr-xr-x   83  1006  1006    3072  May  20  15:35  local-dist files
    lrwxrwxrwx    1  root  wheel     13  Jun   1   2001  packages -> i386/packages
    lrwxrwxrwx    1  root  wheel     24  Jun   1   2001  ports -../FreeBSD-current/ports
    lrwxrwxrwx    1  root  wheel      5  Jun   1   2001  ports-current -> ports
    lrwxrwxrwx    1  root  wheel      5  Jun   1   2001  ports-stable -> ports
    drwxr-xr-x    4  1006  1006     512  Apr   9  10:37  sparc64
    

    The directories alpha, i386, ia64, and sparc64, contain packages (not ports) for the corresponding architecture. dist files contains a large number of the original sources for the third-party packages; it's intended as a ''last resort'' location if you can't find them at other locations.

    The directory local-dist files, is used by people working on the Ports Collection; you don't normally need anything from these directories. The important directories for you are ports, ports-current, and ports-stable. Currently these are really all the same directory, but things may not remain like that.

    Getting back to your emacs, port: you would find it in the directory /pub/Free-BSD/ports/ports/editors/ . Note the final / in that directory name: if you leave it out, ftp prints an error message and exits. Here's what might happen:

    $ ftp ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/ports/editors/
    Connected to ftp.beastie.tdk.net.
    220 ftp.beastie.tdk.net FTP server (Version 6.00LS) ready.
    331 Guest login ok, send your email address as password.
    230- The FreeBSD mirror at Tele Danmark Internet.
    ...much blurb omitted
    250 CWD command successful.
    250 CWD command successful.
    ftp> ls
    229 Entering Extended Passive Mode (|||55649|)
    150 Opening ASCII mode data connection for '/bin/ls'.
    total 704
    
    drwxr-xr-x  3  1006  1006  512  May  20  10:07  emacs
    drwxr-xr-x  4  1006  1006  512  May  20  10:08  emacs20
    drwxr-xr-x  4  1006  1006  512  May  20  10:08  emacs20-dl
    drwxr-xr-x  4  1006  1006  512  May  20  10:08  emacs20-mule-devel
    drwxr-xr-x  3  1006  1006  512  May  20  10:08  emacs21
    drwxr-xr-x  2  1006  1006  512  May  20  10:08  eshell-emacs20
    

    This shows that your files will be in the directory emacs21. You can get them with the ftp mget, command:

    ftp> mget emacs21
    mget emacs21/files [anpqy?]? a           answer a for all files
    Prompting off for duration of mget.
    ftp: local: emacs21/files: No such file or directory
    ftp: local: emacs21/Makefile: No such file or directory
    (etc)
    

    This happens because you need to create the destination directory manually. Try again:

    ftp> !mkdir emacs21                      create the local directory
    ftp> mget emacs21
    mget emacs21/files [anpqy?]? a
    Prompting off for duration of mget.
    229 Entering Extended Passive Mode (|||57074|)
    550 emacs21/files: not a plain file.
    229 Entering Extended Passive Mode (|||57085|)
    150 Opening BINARY mode data connection for 'emacs21/Makefile'   (2185 bytes).
    100%  |*************************************|   2185   2.34 MB/s   00:00 ETA
    226 Transfer complete.
    (etc)
    

    You get one of these for each file transferred. But note the error message: not a plain file. emacs21/files, is a directory, so we need to get it separately:

    ftp> !mkdir emacs21/files
    ftp> mget emacs21/files
    mget emacs21/files/patch-lib-src:Makefile.in [anpqy?]? a
    Prompting off for duration of mget.
    229 Entering Extended Passive Mode (|||57258|)
    150 Opening BINARY mode data connection for 'emacs21/files/patch-lib-src: Make file. in '(908 bytes).
    100%  |*************************************|      908  1.64 MB/s       00:00 ETA
    226 Transfer complete.
    (etc)
    

    Note that the ftp command specifies the URL of the directory. It must have a trailing /, otherwise ftp will complain. This form is supported by FreeBSD ftp but many other ftp clients will require you to do it in two steps:

    # ftp ftp.EreeBSD.org
    Connected to ftp.beastie.tdk.net.
    (etc)
    ftp> cd /pub/FreeBSD/ports/ports/editors
    250 CWD command successful.
    

    What's in that port?

    One problem with the Ports Collection is the sheer number. It can be difficult just to find out what they're supposed to do. If you build all the ports, you'll be busy for weeks, and there's no way you could read all the documentation in one lifetime. Where can you get an overview? Here are some suggestions. In each case, you should have the directory /usr/ports, as your current working directory.

  • There's an index in /usr/ports/INDEX. If you have updated the ports tree, you can make the index with the following commands:
    #  cd /usr/ports
    #  make index
    

    index, is the name of a target, the part of a rule that identifies it. It's usually either a file name or an abbreviation for an operation to perform. We'll see a number of make, targets in the course of the book.

    The index is intended for use by other programs, so it's written as a single long line per package, with fields delimited by the vertical bar character (|). Here are two lines as an example, wrapped over three lines to fit on the page:

    mp3asm-0.1.3|/usr/ports/audio/mp3asm|/usr/local|MP3 frame level editor|/usr/port
    s/audio/mp3asm/pkg-descr|ports@FreeBSD.org|audio| autoconf213-2.13.000227_1||
    htt p://mp3asm.sourceforge.net/
    mp3blaster-3.0p8|/usr/ports/audio/mp3blaster|/usr/local|MP3 console ncurses-base
    dplayer|/usr/ports/audio/mp3blaster/pkg-descr|greid@FreeBSD.org|audio|||
    http:// www.stack.nl/~brama/mp3blaster.html
    

    You'll probably want to process it with other tools.

  • You can print the index with the following commands:
    #  cd /usr/ports
    #  make print-index | lpr
    

    Note that there are about 1,000 pages of output, which look like this:

    Port:    zip-2.3_1
    Path:    /usr/ports/archivers/zip
    Info:    Create/update ZIP files compatible with pkzip
    Maint:   ache@FreeBSD.org
    Index:   archivers
    B-deps:  unzip-5.50
    R-deps:
    
  • You can search for a specific keyword with the search target. For example, to find ports related to Emacs, you might enter:
    #  cd /usr/ports
    #  make search key=Emacs | less
    

    Pipe the output through less, it can be quite a lot.

  • You can build a series of nearly 10,000 html, pages like this:
    #  cd /usr/ports
    #  make readmes
    

    You can then browse them at the URL file:///usr/ports/README.html.

  • Getting the source archive

    You'll see from the above example that there are not many files in the port. Most of the files required to build the software are in the original source code archive (the "tar ball"), but that's not part of the port.

    There are a number of places from which you can get the sources. If you have a CD-ROM set, many of them are scattered over the CD-ROMs, in the directory /cdrom/ports/distfiles, on each CD-ROM. The Ports Collection Make files look for them in this directory (another good reason to mount your CD-ROM on /cdrom), and also in /usr/ports/distfiles.

    If you don't have the source tar ball, that's not a problem. Part of the function of the Ports Collection is to go out on the Net and get them for you. This is completely automatic: you just type make, and the build process gets the source archive for you and builds it. Of course, you must be connected to the Internet for this to work.

    If you mount your CD-ROM elsewhere (maybe because you have more than one CD-ROM drive, and so you have to mount the CD-ROM on, say, /cd4), the Make files will not find the distribution files and will try to load the files from the Internet. One way to solve this problem is to create a symbolic link from /cd4/ports/distfiles, to /usr/ports/distfiles. The trouble with this approach is that you will then no longer be able to load new distribution files into /usr/ports/distfiles, because it will be on CD-ROM. Instead, do:

    #  cd /cd4/ports/distfiles
    #  mkdir -p /usr/ports/distfiles       make sure you have a distfiles directory
    #  for i in *; do
    >  ln -s /cd4/ports/distfiles/$i /usr/ports/distfiles/$i
    >  done
    

    If you're using csh, or tcsh, enter:

    # cd /cd4/ports/distfiles
    # mkdir -p /usr/ports/distfiles       make sure you have a distfiles directory
    # foreach i (*)
    ?  ln -s /cd4/ports/distfiles/$i /usr/ports/distfiles/$i
    ? end
    

    This creates a symbolic link to each distribution file, but if the file for a specific port isn't there, the Ports Collection can fetch it and store it in the directory.

    Building the port

    Once you have the skeleton files for the port, the rest is simple. Just enter:

    #  cd /usr/ports/editors/emacs21
    #  make
    #  make install
    ====> To enable menubar fontset support, define WITH_MENUBAR_FONTSET
    >> emacs-21.2.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
    >> Attempting to fetch from ftp://ftp.gnu.org/gnu/emacs/.
    ===>   Extracting for emacs-21.2_1
    >> Checksum OK for emacs-21.2.tar.gz.
    ===>     emacs-21.2_1 depends on executable: gmake - found
    ===>     emacs-21.2_1 depends on executable: autoconf213 - not found
    ===>      Verifying install for autoconf213 in /usr/ports/devel/autoconf213
    ===>   Extracting for autoconf213-2.13.000227_2
    >> Checksum OK for autoconf-000227.tar.bz2.
    ===>     autoconf213-2.13.000227_2 depends on executable: gm4 - not found
    ===>      Verifying install for gm4 in /usr/ports/devel/m4
    ===>   Extracting for m4-1.4_1
    >> Checksum OK for m4-1.4.tar.gz.
    ===>   Patching for m4-1.4_1
    ===>   Applying FreeBSD patches for m4-1.4_1
    ===>   Configuring for m4-1.4_1
    creating cache ./config.cache
    checking for mawk... no
    (etc)
    

    It's a good idea to perform the make, step first: make install, does not always build the package.

    Port dependencies

    Sometimes, it's not enough to build a single port. Many ports depend on other ports. If you have the complete, up-to-date ports tree installed on your systcode, the Ports Collection will take care of this for you: it will check if the other port is installed, and if it isn't, it will install it for you. For example, tkdesk, depends on tk, tk depends on tcl. If you don't have any of them installed, and you try to build tkdesk, it will recursively install tk and tcl for you.

    Package documentation

    Once you have installed your port, you'll want to use it. In almost every case, that requires documentation. Most packages have documentation, but unfortunately it's not always obvious where it is. In some cases, the port doesn't install all the documentation.

    More generally, there are the following possibilities:

  • If the port includes man pages, they will be installed in /usr/X11R6/man, if the package is related to X, and /usr/local/man, if they are not. Typically installing the man pages is the last thing that happens during the installation, so you should see it on the screen. If not, or if you want to check, you can have a look at the package list:
    $ cd /var/db/pkg
    $ pkg_info -L emacs-21.2_l|grep /man/
    /usr/local/man/man1/ctags.1.gz
    /usr/local/man/man1/emacs.1.gz
    /usr/local/man/man1/etags.1.gz
    /usr/local/man/man1/gfdl.1.gz
    

    You don't need to change the directory to /var/db/pkg, but if you do, you can use file name completion to finish the name of the package. We use /man/ as the search string, and not simply man, because otherwise other files might match as well.

  • If the package includes GNU info pages, you can use the same method to look for them:
    $ pkg_info -L emacs-21.2_l|grep /info/
    /usr/local/info/ada-mode
    /usr/local/info/autotype
    /usr/local/info/ccmode
    /usr/local/info/cl (many more)
    

    This isn't normally necessary, though: if you're using GNU info, the index page will be updated to include the package.

  • If the package includes hard copy documentation, it may or may not be included in the port. The Emacs, documentation also includes a user's guide and a programmer's guide. The user's guide, all 640 pages of it, is in the directory man of the Emacs build directory, but it doesn't get built during installation. This is typical of most ports. In this case you'll have to build the documentation yourself.
  • Getting binary-only software

    A lot of software doesn't need to be ported. For example, if you want . But how, do you install it? Netscape's installation procedures are getting better, but they still leave something to be desired.

    The answer's simple: take the port! Although Netscape comes only in binary form, the port handles getting the correct version and installing it for you. Another advantage to using a port instead of installing the package manually is that the port installs the software as a FreeBSD package, which makes it much easier to remove the software later.

    This method can be used to install some other software as well, for example Star Office. The moral is simple: always check the Ports Collection before getting a software package from the Net.

    Maintaining ports

    Once you install a port, you might consider that to be the end of the story. That's seldom the case. For example:

  • You might need to replace a port with a newer version. How do you do it? We'll look at that below.
  • One day, you might find your disk fills up, so you go looking for old ports you don't use anymore. We'll look at some utility commands on page 178.
  • Upgrading ports

    From time to time, new versions of software will appear. There are a number of approaches to upgrading:

  • You can remove the old version of the port and install a new version. The trouble here is that removing the old version might remove any configuration files as well.
  • You can install a new version without removing the old version. The trouble here is that you end up with two entries in the packages database /var/db/pkg:
    $ pkg_info | grep emacs
    emacs-21.1_5  GNU editing macros
    emacs-21.2_1  GNU editing macros
    

    Clearly you don't need emacs-21.15 anymore. In fact, it's not complete anymore, because the program /usr/local/bin/emacs has been overwritten by the new version. But you can't remove it either: that would remove components of emacs-21.2_1, which you want to keep. On the other hand, if you don't remove it, you are left with nearly 50 MB of disk space used up in the directory /usr/local/share/emacs/21.1.

  • You can use portupgrade, a program that does some of the upgrading automatically. We'll look at this below.
  • Using portupgrade

    Portupgrade is—what else?—a port. Install it in the usual manner:

    # cd /usr/ports/sysutils/portupgrade
    # make install
    

    Before you can perform the upgrade, you should first back up /var/db/pkg, then build a ports database with pkgdb. A typical build might look like this:

    # cd /var/db
    # tar czvf db.pkg.tar.gz pkg/
    # pkgdb -F
    [Updating the pkgdb <format:bdb1_btree> in /var/db/pkg ... - 181 packages
    found (-5 +92)  (...)...............done]
    Checking the origin of AbiWord-1.0.3
    Checking the origin of ImageMagick-5.5.1.1
    Checking the origin of ORBit-0.5.17
    ...
    Checking the origin of xv-3.10a_3
    Checking the origin of zip-2.3_1
    Checking for origin duplicates
    Checking AbiWord-1.0.3
    Checking ImageMagick-5.5.1.1
    Stale dependency: ImageMagick-5.5.1.1 -> ghostscript-gnu-7.05_3:
    ghostscript-gnu-6.52_4 (score:64%) ?  ([y]es/[n]o/[a]ll)   [no] y
    Fixed. (-> ghostscript-gnu-6.52_4)
    Checking ORBit-0.5.17 Checking XFree86-4.2.0_1,1
    Checking bonobo-1.0.21_1
    Stale dependency: bonobo-1.0.21_1 -> ghostscript-gnu-7.05_3:
    ghostscript-gnu-6.52_4 ? ([y]es/[n]o/[a]ll)   [yes]        Enter pressed
    Fixed. (-> ghostscript-gnu-6.52_4)
    Checking cdrtools-1.11.a28
    ...
    Checking xv-3.10a_3
    Checking zip-2.3_1
    Regenerating +REQUIRED_BY files
    Checking for cyclic dependencies
    

    In this example, the port ghostscript-gnu-7.05 3 had been replaced by the earlier version ghostscript-gnu-6.52_4, since ghostscript Release 7 has some annoying bugs. The dialogue shows how pkgdb, recognized the discrepancy, and how it recovered from it.

    Now you can start the upgrade. To upgrade a specific port, simply specify its base name, without the version number. This example uses the -v, option to show additional information:

    # portupgrade -v bison
    ---> Upgrade of devel/bison started at: Mon, 04 Nov 2002 13:20:52 +1030
    ---> Upgrading 'bison-1.35_1' to 'bison-1.75' (devel/bison)
    ---> Build of devel/bison started at: Mon, 04 Nov 2002 13:20:52 +1030
    ... normal port build output
    ===> Registering installation for bison-1.75
    make clean issued by portupgrade
    ===> Cleaning for libiconv-1.8_2
    ===> Cleaning for gettext-0.11.5_1
    ...
    ---> Removing the temporary backup files
    ---> Installation of devel/bison ended at: Mon, 04 Nov 2002 13:23:00 +1030 (consume
    d00:00:06)
    ---> Removing the obsoleted dependencies
    ---> Cleaning out obsolete shared libraries
    ---> Upgrade of devel/bison ended at: Mon, 04 Nov 2002 13:23:01 +1030 (consumed 00:
    02:08)
    ---> Reporting the results ( + :succeeded / -:ignored / *:skipped / !:failed)
    +devel/bison (bison-1.35_1)
    

    If the port is already up to date, you'll see something like this:

    # portupgrade -v perl-5.8.0_3
    ** No need to upgrade 'perl-5.8.0_3'   (>= perl-5.8.0_3).  (specify -f to force)
    ---> Reporting the results ( + :succeeded / -:ignored / *:skipped / !:failed)
    -lang/perl5.8 (perl-5.8.0_3)
    

    To upgrade all ports, use the command:

    # portupgrade -a
    

    Controlling installed ports

    We've already seen the program pkg_add, when installing pre-compiled packages. There are a number of other pkg_ programs that can help you maintain installed ports, whether they have been installed by pkg_add, or by make install from the Ports Collection:

  • pkg_info, tells you which ports are installed. For example:
    $ pkg_info | less
    AbiWord-1.0.3        An open-source, cross-platform WYSIWYG word proces
    ImageMagick-5.5.1.1  Image processing tools (interactive optional--misc
    ORBit-0.5.17         High-performance CORBA ORB with support for the C
    XFree86-4.2.0_1,1    X11/XFree86 core distribution (complete, using min
    ... etc
    bash-2.05b.004       The GNU Bourne Again Shell
    bison-1.75           A parser generator from FSF, (mostly) compatible w
    bonobo-1.0.21_1      The component and compound document system for GNO
    cdrtools-1.11.a28    Cdrecord, mkisofs and several other programs to re
    ... etc
    elm-2.4ME+22         ELM Mail User Agent
    elm-2.4ME+32         ELM Mail User Agent
    

    Note that the last two entries in this example show that two versions of elm, are installed. This can't be right; it happens when you install a new version without removing the old version and without running portupgrade. We'll discuss this matter further below.

  • If you have the ports tree installed, you can use pkg_version, to check whether your ports are up to date. pkg_version, is a little cryptic in its output:
    AbiWord-gnome=
    ImageMagick<
    ORBit<
    Wingz=
    XFree86<
    x2x-1.28?
    The symbols to the right of the package names have the following meanings:
    =The installed version of the package is current.
    <The installed version of the package is older than the current version.
    >The installed version of the package is newer than the current version. This situation can arise with an out-of-date index file, or when testing new ports.
    ?The installed package does not appear in the index. This could be due to an out of date index o repackage that has not yet been committed.
    *There are multiple versions of a particular software package listed in the index file.
    !The installed package exists in the index but for some reason, pkgversion, was unable to compare the version number of the installed package with the corresponding entry in the index.
  • There are two ways to remove a port: if you've built it from source, and you're in the build directory, you can write:
    # make deinstall
    

    Alternatively, you can remove any installed package with pkg_delete. For example, the list above shows two versions of the elm, mail user agent. To remove the older one, we enter:

    #  pkg_delete elm-2.4ME+22
    File Vusr/local/man/manl/answer.l' doesn't really exist.
    Unable to completely remove file '/usr/local/man/manl/answer.1'
    File Vusr/local/man/manl/checkalias.l' doesn't really exist.
    Unable to completely remove file '/usr/local/man/manl/checkalias.l'
    ... etc
    Couldn't entirely delete package (perhaps the packing list is incorrectly specified?)
    

    In this case, it looks as if somebody has tried to remove the files before, so pkg_delete, couldn't do so.

    Another problem with pkg_delete, is that it might delete files of the same name that have been replaced by newer packages. After performing this operation, we try:

    $ elm
    bash: elm: command not found
    

    Oops! We tried to delete the old version, but we deleted at least part of the new version. Now we need to install it again.

    The moral of this story is that things aren't as simple as they might be. When you install a new version of a package, you may want to test it before you commit to using it all the time. You can't just go and delete the old version. One possibility would be to install the new package, and try it out. When you've finished testing, delete both, packages and re-install the one you want to keep.

  • Keeping track of updates

    The best way to find out about updates is to subscribe to the FreeBSD-ports mailing list. That way, you will get notification every time something changes. If you're tracking the ports tree with CVSup, you also get the updates to the ports tree automatically. Otherwise you will have to download the port. In either case, to update your installed port, just repeat the build.

    Submitting a new port

    The Ports Collection is constantly growing. Hardly a day goes by without a new port being added to the list. Maybe you want to submit the next one? If you have something interesting that isn't already in the Ports Collection, you can find instructions on how to prepare the port in the FreeBSD Porter's Handbook. The latest version is available on the FreeBSD web site, but you'll also find it on your system as /usr/share/doc/en/porters-handbook/index.html.

    Вернуться к учебному плану