Installing packages in Free BSD

in Free BSD using packages & ports




FreeBSD provides two complementary technologies for installing third-party software on your system: the FreeBSD Ports Collection (for installing from source), and packages (for installing from pre-built binaries). Either method may be used to install the newest version of your favorite applications from local media or straight off the network. By installing from the port, you can
tweak the compilation options to (for example) generate code that is specific to a Pentium 4 or Athlon processor.By building from the port you do not have to accept the default options, and can set them yourself.



Finding Your Application :
Before you can install any applications you need to know what you want, and what the application is called.


The FreeBSD web site maintains an up-to-date searchable list of all the available applications, at The ports are divided into categories, and you may either search for an application by name (if you know it), or see all the applications available in a category.


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



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



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


Index: sysutils




  1. Installing 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.


# ftp -a

Connected to

220 FTP server (Version 6.00LS) ready.

331 Guest login
ok, send your email address as password.


230- This
machine is in Vienna, VA, USA, hosted by Verio.

Questions? E-mail



230 Guest login
ok, access restrictions apply.

Remote system
type is UNIX.

Using binary mode
to transfer files.

ftp> cd

250 CWD command

ftp> get

lsof-4.56.4.tgz remote: lsof-4.56.4.tgz

200 PORT command

150 Opening
BINARY mode data connection for ‘lsof-4.56.4.tgz’ (92375 bytes).

|**************************************************| 92375
00:00 ETA

226 Transfer

92375 bytes
received in 5.60 seconds (16.11 KB/s)

ftp> exit

# pkg_add


If you do not have a source of local packages (such as a FreeBSD CD-ROM set) then it will probably be easier to use the -r option to pkg_add.


# pkg_add -r lsof




Managing Packages


# pkg_info lsof

# pkg_version lsof

# pkg_delete lsof

All package information is stored within the /var/db/pkg directory. The installed file list and descriptions of each package can be found within files in this directory.



5. Using 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. 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.


1. Install the net/cvsup-without-gui package:


# pkg_add -r cvsup-without-gui


2. Run cvsup:


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


Alternate method:- Portsnap Method


# pkg_add -r portsnap


# mkdir /usr/ports


# portsnap fetch


# portsnap extract


# portsnap update




ii) Installation


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

>> Attempting to fetch from

===> Extracting for lsof-4.57

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

===> Building for lsof-4.57

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

output snipped]

===> Generating temporary packing list

===>Compressing manual pages for lsof-4.57

===>Registering installation for lsof-4.57


This porthas installed the following binaries which execute with increased privileges.

#It is a good idea to delete the working subdirectory, which contains all the temporary files used during compilation. Not only does it consume valuable disk space, but it would also cause problems later when upgrading to the newer version of the port.


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

Iii) Upgrading Ports


Once you have updated your Ports Collection, before attempting a port upgrade, you should check
/usr/ports/UPDATING. This file describes various issues and additional steps users may encounter and need to perform when updating a port.


# cd /usr/ports/ports-mgmt/portupgrade

# make install clean



# portupgrade -ai

# portupgrade -R firefox


To free the disk space consumed while installing packages


# portsclean -C





2 responses to “Installing packages in Free BSD

  1. Pingback: Geek Lectures - Things geeks should know about » Blog Archive » Installing packages in Free BSD

  2. I recently ran into a problem when I had installed 6.0-RELEASE from an old CD-R laying around, it goes like this…

    1.) Installed a ‘minimum’ installation with no ports or packages added.

    2.) This is a problem since 6.0-RELEASE is not on ftp mirrors therefore no “pkg_add -r” for me.

    3.) Portsnap to the rescue!

    # mkdir /usr/ports

    # portsnap fetch; portsnap extract; portsnap update

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s