FreeBsd Ports/Packages

New to FreeBsd and only familiar with RPM ? This will article will guide you through how to install third-party applications and system tools using ports and packages

Ports

Port is a technology used to install from source.

Each Port is a collection of scripts that when executed, automatically download source of softwares from the Internet, patches, configures if necessary, compiles and install it. Any dependencies on other applications or libraries a port may have are also installed for the user.

Each port, or software package, is maintained by a “port maintainer”, an individual who is responsible for staying current with the latest software developments. Anyone is welcome to become a port maintainer by contributing their favorite piece of software to the collection. One may also choose to adopt and maintain an existing port that has no maintainership.

Packages

Packages is another techInology used to install from pre-built binaries.
For any given application, the FreeBSD package for that application is a single file which you must download. The package contains pre-compiled copies of all the commands for the application, as well as any configuration files or documentation. A downloaded package file can be manipulated with FreeBSD package management commands, such as pkg_add, pkg_delete, pkg_info, and so on. Installing a new application can be carried out with a single command.

Both packages and ports understand dependencies. Suppose you want to install an application that depends on a specific library being installed. Both the application and the library have been made available as FreeBSD ports and packages. If you use the pkg_add command or the ports system to add the application, both will notice that the library has not been installed, and automatically install the library first.

Given that the two technologies are quite similar, you might be wondering why FreeBSD bothers with both. Packages and ports both have their own strengths, and which one you use will depend on your own preference.

Find your application to Install

Suppose you want to install lsof using port
If you know the exact name of the port, but just need to find out which category it is in, you can use the whereis command. Simply type whereis file, where file is the program you want to install. If it is found on your system, you will be told where it is, as follows:


# whereis lsof

lsof: /usr/ports/sysutils/lsof

This tells us that lsof (a system utility) can be found in the
/usr/ports/sysutils/lsof directory.

Yet another way to find a particular port is by using the Ports Collection’s built-in search mechanism. To use the search feature, you will need to be in the /usr/ports directory. Once in that directory, run make search name=program-name where program-name is the name of the program you want to find. For example, if you were looking for lsof:


# cd /usr/ports

# make search name=lsof

Port:   lsof-4.56.4

Path:   /usr/ports/sysutils/lsof

Info:   Lists information about open files (similar to fstat(1))

Maint:  obrien@FreeBSD.org

Index:  sysutils

B-deps:

R-deps:

For in-depth searching you can also use make search key=string where string is some text to search for. This searches port names, comments, descriptions and dependencies and can be used to find ports.

To begin, change to the directory for the port you want to install:


# cd /usr/ports/sysutils/lsof

Once inside the lsof directory, you will see the port skeleton. The next step is to compile, or “build”, the port. This is done by simply typing make at the prompt. Once you have done so, you should see something like this:


# make

>> lsof_4.57D.freebsd.tar.gz doesn't seem to exist in /usr/ports/distfiles/.

>> Attempting to fetch from ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/.

===>  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 next step is to install the port. In order to install it, you simply need to tack one word onto the make command, and that word is install:


# 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.

It is always good idea to delete the working directory.


# make clean

===>  Cleaning for lsof-4.57

Note: You can save two extra steps by just running “make install clean” instead of make, make install and make clean as three separate steps.
This is how you install a utility using ports now you need to know more about Packages before we proceed with Ports.

How to use Package system

Install a package

You can use the pkg_add utility to install a FreeBSD software package from a local file or from a server on the network.


# pkg_add -r lsof

This will cause the utility to automatically determine the correct object format and release and then fetch and install the package from an FTP site. If you want to some alternative FreeBSD Packages Mirror, instead of the main distribution site, you have to set PACKAGESITE accordingly.
It is possible to change this behavior by overriding the PACKAGESITE environment variable. For example, if you run a FreeBSD 5.4-RELEASE system, by default pkg_add will try to fetch packages from


ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-5.4-release/Latest/. If you want to force pkg_add to download FreeBSD 5-STABLE packages,
set PACKAGESITE to ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-5-stable/Latest/

Managing Packages


pkg_info is a utility that lists and describes the various packages installed.

cvsup-16.1          A general network file distribution system optimized for CV

docbook-1.2         Meta-port for the different versions of the DocBook DTD

pkg_version is a utility that summarizes the versions of all installed packages. It compares the package version to the current version found in the ports tree.

The symbols in the second column indicate the relative age of the installed version and the version available in the local ports tree.

Symbol Meaning

= The version of the installed package matches the one found in the local ports tree.

The installed version is newer than the one found in the local ports tree.

(The local ports tree is probably out of date.)

? The installed package cannot be found in the ports index.

(This can happen, for instance, if an installed port is removed from the Ports Collection or renamed.)

* There are multiple versions of the package.

Deleting a Package

To remove a previously installed software package, use the pkg_delete utility.


# pkg_delete xchat-1.7.1

Now lets come again to Ports, below are the steps to obtain Ports if its not installed in the machine.

Obtaining the Ports Collection.

Before you can install ports, you must first obtain the Ports Collection–which is essentially a set of Makefiles, patches, and description files placed in /usr/ports.

When installing your FreeBSD system, sysinstall asked if you would like to install the Ports Collection. If you chose no, you can follow these instructions to obtain the ports collection:

CVSup Method

This is a quick method for getting and keeping your copy of the Ports Collection up to date using CVSup. If you want to learn more about CVSup, see Using CVSup.

Make sure /usr/ports is empty before you run CVSup for the first time! If you already have the Ports Collection present, obtained from another source, CVSup will not prune removed patch files.

Install the net/cvsup-without-gui package:


#pkg_add -r cvsup-without-gui

#cvsup -L 2 -h cvsup.FreeBSD.org /usr/share/examples/cvsup/ports-supfile

Change cvsup

FreeBSD.org to a CVSup server near you. See CVSup Mirrors for a complete listing of mirror sites. Note: One may want to use his own ports-supfile, for example to avoid the need of passing the CVSup server on the command line.


1. In this case, as root, copy /usr/share/examples/cvsup/ports-supfile to a new location,

such as /root or your home directory.

2. Edit ports-supfile.

3. Change CHANGE_THIS.FreeBSD.org to a CVSup server near you.

4. And now to run cvsup, use the following:

# cvsup -L 2 /root/ports-supfile

3. Running the cvsup command later will download and apply all the recent changes to your Ports Collection,

except actually rebuilding the ports for your own system.

Portsnap Method

Portsnap is an alternative system for distributing the Ports Collection. It was first included in FreeBSD 6.0. On older systems, you can install it from sysutils/portsnap package:


# pkg_add -r portsnap

1. Since FreeBSD 6.1-RELEASE and with recent versions of the Portsnap port or package, you can safely skip this step. The /usr/ports will be created automatically at first use of the portsnap command. With previous versions of Portsnap, you will have to create an empty directory /usr/ports if it does not exists:

2. Download a compressed snapshot of the Ports Collection into /var/db/portsnap. You can disconnect from the Internet after this step, if you wish.


# portsnap fetch

3. If you are running Portsnap for the first time, extract the snapshot into /usr/ports:


# portsnap extract

If you already have a populated /usr/ports and you are just updating, run the following command instead:


# portsnap update

Sysinstall Method

This method involves using sysinstall to install the Ports Collection from the installation media. Note that the old copy of Ports Collection from the date of the release will be installed. If you have Internet access, you should always use one of the methods mentioned above.


1. As root

# sysinstall

2. Scroll down and select Configure, press Enter.

3. Scroll down and select Distributions, press Enter.

4. Scroll down to ports, press Space.

5. Scroll up to Exit, press Enter.

6. Select your desired installation media, such as CDROM, FTP, and so on.

7. Scroll up to Exit and press Enter.

8. Press X to exit sysinstall

Installing using Ports

The Ports Collection makes an assumption that you have a working Internet connection. If you do not, you will need to put a copy of the distfile into /usr/ports/distfiles manually.

In some rare cases, users may need to acquire the tarballs from a site other than the MASTER_SITES (the location where files are downloaded from). You can override the MASTER_SITES option with the following command:


# cd /usr/ports/directory

# make MASTER_SITE_OVERRIDE=ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/ fetch

Removing Installed Ports


# pkg_delete lsof-4.57
Upgrading Ports
 # pkg_version -v

Before attempting a port upgrade, you should check /usr/ports/UPDATING

Upgrade Ports using Portupgrade

The portupgrade utility is designed to easily upgrade installed ports. It is available from the sysutils/portupgrade port. Install it like any other port, using the make install clean command:


# cd /usr/ports/sysutils/portupgrade

# make install clean

Scan the list of installed ports with the pkgdb -F command and fix all the inconsistencies it reports. It is a good idea to do this regularly, before every upgrade.

When you run portupgrade -a, portupgrade will begin to upgrade all the outdated ports installed on your system. Use the -i flag if you want to be asked for confirmation of every individual upgrade.


# portupgrade -ai

If you want to upgrade only a certain application, not all available ports, use portupgrade pkgname. Include the -R flag if portupgrade should first upgrade all the ports required by the given application.


# portupgrade -R firefox,

To use packages instead of ports for installation, provide -P flag. With this option portupgrade searches the local directories listed in PKG_PATH, or fetches packages from remote site if it is not found locally. If packages can not be found locally or fetched remotely, portupgrade will use ports. To avoid using ports, specify -PP.


# portupgrade -PR gnome2

To just fetch distfiles (or packages, if -P is specified) without building or installing anything, use -F

Upgrading Ports using Portmanager

Portmanager is another utility for easy upgrading of installed ports. It is available from the sysutils/portmanager port:


# cd /usr/ports/sysutils/portmanager

# make install clean

All the installed ports can be upgraded using this simple command:


# portmanager -u

You can add the -ui flag to get asked for confirmation of every step Portmanager will perform. Portmanager can also be used to install new ports on the system. Unlike the usual make install clean command, it will upgrade all the dependencies prior to building and installing the selected port.


# portmanager x11/gnome2

If there are any problems regarding the dependencies for the selected port, you can use Portmanager to rebuild all of them in the correct order. Once finished, the problematic port will be rebuilt too.


# portmanager graphics/gimp -f

Ports and Disk Space

Using the Ports Collection will use up disk space over time. After building and installing software from the ports, you should always remember to clean up the temporary work directories using the make clean command. You can sweep the whole Ports Collection with the following command:


# portsclean -C

You will accumulate a lot of old source distribution files in the distfiles directory over time. You can remove them by hand, or you can use the following command to delete all the distfiles that are no longer referenced by any ports:


# portsclean -D

Or to remove all distfiles not referenced by any port currently installed on your system:


# portsclean -DD

Note: The portsclean utility is part of the portupgrade suite.

Post Installation

To know more about the package you have installed now.


# pkg_info -L newpackage-1.0.0 | less

# pkg_info | grep -i newpackage

If the application has a web site, check it for additional documentation, frequently asked questions, and so forth. If you are not sure of the web site address it may be listed in the output from


# pkg_info newpackage-1.0.0

VN:F [1.9.6_1107]
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.6_1107]
Rating: 0 (from 0 votes)
Using FreeBSD ports and packages, 7.0 out of 10 based on 1 rating
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Live
  • StumbleUpon
  • Twitter
  • Yahoo! Buzz
  • Reddit
  • Technorati