Chapter 8. The package collection

Table of Contents
8.1. Installing the package collection
8.2. Updating the package collection
8.3. Example: installing a program from source
8.4. Example: installing a binary package
8.5. Package management commands
8.6. Quick Start Packaging Guide

The NetBSD package collection is a collection of tools that greatly simplify the compilation and installation of a huge quantity of free software for Unix systems. Only one or two commands are required to install a perfectly configured and working package.

The first contact with the NetBSD package system can generate a little confusion: apparently there are different commands that do the same thing. The question is actually very simple: here are two ways to install a program. You can

The two aforementioned methods both require that someone else has "created a package", i.e. has ported and configured a program for NetBSD. Although the package collection comprises more that 1000 programs, it is possible that the one that you want is still not included. In this case you can compile it without using the package system and, once you get it working, create a package that can be added to the collection: other users will benefit from your work.

8.1. Installing the package collection

Before installing a program from source, you should download and install the package collection from the NetBSD site or from the mirror of your choice. This is described in the following steps.

  1. Download the latest version of the package system sources, which include all the necessary makefiles and configuration files, from ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-current/tar_files/. The file to be downloaded is pkgsrc.tar.gz.

  2. Remove the existing collection from your hard disk (if you already have installed it) with the following command:

    # cd /usr
    # rm -rf pkgsrc
    	  

  3. Install the collection that you have downloaded:

    # tar -xzvpf pkgsrc.tar.gz -C /usr    
    The execution of the previous command can last many minutes, because of the huge number of (small) files that are extracted. At the end, the framework required for the installation of new programs is ready and you can start installing them.

    Note: by now it is probably clear that the previous commands installed the configuration files required for the automatic installation of programs on your system: you have not yet installed the programs! Basically, the system now has a list of the available packages and the instructions to fetch, compile and install them.

When you have installed the package collection you can browse it with Lynx or Netscape and read the details and the descriptions of all the available packages and package categories. For example:

$ cd /usr/pkgsrc
$ lynx README.html
      

8.2. Updating the package collection

The package collection is frequently updated: you can find a new version on the ftp site almost weekly. To update the collection on your system follow the same instructions as for first time installation.

Sometimes, when updating the package collection, it will be necessary to update the "pkgtools" utilities too. You can easily spot if you need to do it: when you try to install a program the package system complains that your pkgtools are outdated.

# make
===> Validating dependencies for gqmpeg-0.6.3
Your package tools need to be updated to 2000/02/02 versions.
The installed package tools were last updated on 1999/01/01.
Please make and install the pkgsrc/pkgtools/pkg_install package.
*** Error code 1    

The easiest way to update is:

# cd /usr/pkgsrc/pkgtools/pkg_install
# make install
    

After this you can resume the installation of the package which issued the original error message.

8.3. Example: installing a program from source

This section describes the installation of an example program: the addnerd application, which simplifies the creation of new accounts on your system. First, cd to the /usr/pkgsrc/sysutils/addnerd directory.

8.4. Example: installing a binary package

I have already explained in the first part of this chapter that the package system can install program from source but can also install binary packages, prepared by someone else for NetBSD. This second form of installation is faster because the compilation of the package is not needed and the tarballs for the binary package are usually smaller and faster to fetch. To install a binary package the package collection is not needed: only the "pkgtools" utilities are needed.

The tarballs for the binary programs usually have the extension .tgz while the source tarballs usually end with .tar.gz.

It is not strictly necessary to download binary packages prior to installation: you can also use ftp://-URLs. For example:

ftp://ftp.netbsd.org/pub/NetBSD/packages/1.4.2/i386/All/tcsh-6.09.00.tgz    

If you don't know what version of the package is available on the FTP site you can even leave out the version inormation and pkg_add will pick the latest version on the FTP server. For example:

# pkg_add ftp://ftp.netbsd.org/pub/NetBSD/packages/1.4.2/i386/All/tcsh    

It is also possible to set PKG_PATH to a ;-separated list of path and URLs and then omit that part for pkg_add:

# PKG_PATH="/cdrom;/usr/pkgsrc/packages/All;ftp://ftp.netbsd.org/pub/NetBSD/packages/1.4.2/i386/All"
export PKG_PATH
# pkg_add tcsh
    

The previous command installs the first tcsh binary package that it finds.

As an example, let's install the texinfo program in precompiled form.

  1. Copy gtexinfo-3.12.tgz in a temporary directory.

  2. Give the following command

    # pkg_add -v gtexinfo-3.12.tgz    

  3. Check that the package has been installed with the command

    # pkg_info    

  4. Remove the file gtexinfo-3.12.tgz from the temporary directory.

Precompiled packages are very practical to use because they require a minimal effort and time for installation, but source packages give more control because their compilation options can be customized. The installation is somewhat longer, because of the compilation, and this could be critical on some (older) platforms.

Before installing a precompiled package with pkg_add, it is better to examine it with the pkg_info command. For example:

# pkg_info -f jpeg-6b.tgz    

It is worth examining the first CWD command, to check where the package is installed (base directory.) The most common base directories are /usr/pkg and /usr/X11R6. If the base directory is not what you want, you can change it with the -p of the pkg_add command. For example, the jpeg-6b.tgz package is installed in /usr/pkg by default, but you can install it in /usr/X11R6 if you extract it with the following command:

# pkg_add -p /usr/X11R6 -v jpeg-6b.tgz    

8.5. Package management commands

The most important commands for package management are:

8.6. Quick Start Packaging Guide

This section (Quick Start Packaging Guide) has been contributed by Jason R. Fink

This section details a quick start method for building relatively small Packages for the NetBSD packaging system. For more details on some of the intricacies on the NetBSD packaging system see Packages.txt in the pkgsrc tree.