Полезная информация

4.3. Getting a FreeBSD Port

There are two ways of getting hold of the FreeBSD port for a program. One requires a FreeBSD CDROM, the other involves using an Internet Connection.

4.3.1. Compiling ports from CDROM

Assuming that your FreeBSD CDROM is in the drive and mounted on /cdrom (and the mount point must be /cdrom), you should then be able to build ports just as you normally do and the port collection's built in search path should find the tarballs in /cdrom/ports/distfiles/ (if they exist there) rather than downloading them over the net.

Another way of doing this, if you want to just use the port skeletons on the CDROM, is to set these variables in /etc/make.conf:

    PORTSDIR=       /cdrom/ports
    DISTDIR=        /tmp/distfiles
    WRKDIRPREFIX=   /tmp

Substitute /tmp for any place you have enough free space. Then, just cd to the appropriate subdirectory under /cdrom/ports and type make install as usual. WRKDIRPREFIX will cause the port to be build under /tmp/cdrom/ports; for instance, games/oneko will be built under /tmp/cdrom/ports/games/oneko.

Note: There are some ports for which we cannot provide the original source in the CDROM due to licensing limitations. In that case, you will need to look at the section on Compiling ports using an Internet connection.

4.3.2. Compiling ports from the Internet

If you do not have a CDROM, or you want to make sure you get the very latest version of the port you want, you will need to download the skeleton for the port. Now this might sound like rather a fiddly job full of pitfalls, but it is actually very easy.

First, if you are running a release version of FreeBSD, make sure you get the appropriate ``upgrade kit'' for your release from the ports web page. These packages include files that have been updated since the release that you may need to compile new ports.

The key to the skeletons is that the FreeBSD FTP server can create on-the-fly tarballs for you. Here is how it works, with the gnats program in the databases directory as an example (the bits in square brackets are comments. Do not type them in if you are trying this yourself!):-

    # cd /usr/ports
    # mkdir databases
    # cd databases
    # ftp ftp.FreeBSD.org
    [log in as `ftp' and give your email address when asked for a
    password. Remember to use binary (also known as image) mode!]
    ftp> cd /pub/FreeBSD/ports/ports/databases
    ftp> get gnats.tar
    [tars up the gnats skeleton for us]
    ftp> quit
    # tar xf gnats.tar
    [extract the gnats skeleton]
    # cd gnats
    # make install
    [build and install gnats]

What happened here? We connected to the FTP server in the usual way and went to its databases sub-directory. When we gave it the command get gnats.tar, the FTP server tarred up the gnats directory for us.

We then extracted the gnats skeleton and went into the gnats directory to build the port. As we explained earlier, the make process noticed we did not have a copy of the source locally, so it fetched one before extracting, patching and building it.

Let us try something more ambitious now. Instead of getting a single port skeleton, we will get a whole sub-directory, for example all the database skeletons in the ports collection. It looks almost the same:-

    # cd /usr/ports
    # ftp ftp.FreeBSD.org
    [log in as `ftp' and give your email address when asked for a
    password. Remember to use binary (also known as image) mode!]
    ftp> cd /pub/FreeBSD/ports/ports
    ftp> get databases.tar
    [tars up the databases directory for us]
    ftp> quit
    # tar xf databases.tar
    [extract all the database skeletons]
    # cd databases
    # make install
    [build and install all the database ports]

With half a dozen straightforward commands, we have now got a set of database programs on our FreeBSD machine! All we did that was different from getting a single port skeleton and building it was that we got a whole directory at once, and compiled everything in it at once. Pretty impressive, no?

If you expect to be installing many ports, it is probably worth downloading all the ports directories.