HowTo: Using FreeBSD Ports

Tutorials

Synopsis

Just like RPM Package Manager, FreeBSD Ports collection is where users and administrators to install application that has been ported for FreeBSD. At the time of writing, there are more than 19,000 ports available. Ports can be searched via official FreeBSD ports page or use one of the following commands on your FreeBSD machine :

# make search name=[port's name]
example: make search name=vim

or

# make search key=[keywords]
example: make search key="text editor"

In this tutorial, you will learn how to install Ports Tree and keeping it up-to-date, as well as install application from ports.

Install Ports Tree

If you did not install ports during FreeBSD Installation, it can be installed using sysinstall command:

  • sysinstall
  • Configure
  • Distributions
  • Ports (space to select) then click OK
  • and follow the rest of the instructions

Keep Ports Tree Up-To-Date

In software development world, everything is ever-changing. Software always get updated because of new features or bug fixes. Your Ports Tree might no longer be up-to-date. In order to ensure your ports tree has the latest collection, it needs to be updated. There are 2 common ways to update Port Trees:

CVSup/csup Method

The example ports-supfile can be found in /usr/share/examples/cvsup/ports-supfile, copy that file to /root/ so that you can modify to fit your setup.

Open /root/ports-supfile and modify CHANGE_THIS.FreeBSD.org to a CVSup near you. After save the file, run the following command:

# csup -L 2 /root/ports-supfile

If you want to use different CVSup server without modifying the ports-supfile, run the following command instead:

# csup -L 2 -h cvsup.FreeBSD.org /root/ports-supfile

Portsnap Method

It is an alternative application for distributing ports collection. It’s more secured and faster since each snapshot is digitally signed and compressed. If Portsnap is not installed on your system, it can be found in /usr/ports/ports-mgmt/portsnap.

There are 3 basic and common portsnap command:

  1. portsnap fetch: to download latest snapshot
  2. portsnap extract: only need if you are running Portsnap for the first time
  3. portsnap update: to update your existing Ports Tree from your recent fetched snapshot

To update your Ports Tree on demand, you can run the following command to fetch and update:

# portsnap fetch update

To update your Ports Tree regularly, you need to add the following line in your root’s crontab entries:

0 3 * * * /usr/sbin/portsnap cron

Install New Application from Ports

There are many ways to install new application, such as compile from source, packages system, or sysinstall. I will show you how to do it for the first two.

Compile From Source

Compiling from source can be as easy as make install. First you need to locate where the application is located inside /usr/ports. If you are not sure, you can use search (see Synopsis).

Example on how to install vim:

cd /usr/ports/editors/vim/ && make install

This method will download the source code and install it from source.

To deinstall  vim:

# cd /usr/ports/editors/vim/ && make deinstall

To reinstall vim:

# cd /usr/ports/editors/vim/ && make reinstall

Please keep in mind, every time you install an application using this method, it will take up some time and space. It will create all the compiled objects in working directory inside its folder. This eventually can fill up your partition. All the downloaded source code also will retain in /usr/ports/distfiles. To clean those files, you need to run this command:

# cd /usr/ports/editors/vim/ && make clean distclean

clean is to clean its working files and distclean is to clean its distribution file(s). Isn’t that pretty straight forward?

Using Packages System

Example on how to install vim:

# pkg_add -r vim

To deinstall vim, you need to know its version number:

# pkg_delete vim-7.2.14

To find out what version vim is installed on your system:

# pkg_info | grep vim
vim-7.2.14          Vi "workalike", with many additional features

Upgrading Installed Application Using Portupgrade

To determine if there is any newer version of installed application in your system, run the following command:

# pkg_version -vIL=
vim-7.2.14                          <   needs updating (index has vim-7.2.14_2)
fusefs-kmod-0.3.9.p1_2              <   needs updating (index has 0.3.9.p1.20080208_3)

This command is to compare all the installed application with your local ports tree. If it has different version (newer or older), it will be listed. Therefore, it’s recommended to keep your ports tree updated.

If you do not have Portupgrade installed in your system, it can be found at /usr/ports/ports-mgmt/portupgrade.

To upgrade all outdated application, run the following command:

# portupgrade -a

To upgrade a specific application, run the following command:

# portupgrade vim

Further Reading

No Comments

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>