Installing Software through Ports

First things first. Make sure your Ports tree is up-to-date. We recommend updating your Ports tree at least once a month. This will ensure that you see a current list of software available through Ports (and will prevent you from getting error messages about files not being available because you're trying to download an outdated version that no longer exists on the remote server). As root,

cvsup /root/ports-supfile

If you don't know what this means or don't have a ports-supfile set up, read this for some basic setup instructions.

The actual installation procedure for software found in Ports is simple and straightforward. If, for example, we wanted to install Mplayer, we would issue the following commands:

cd /usr/ports/multimedia/mplayer
make install clean

That's it. Wait a little while, and you should have a nice fresh install of the desired application.

One thing to note is that every so often you will want to empty the contents of your /usr/ports/distfiles directory. When you install an application through Ports, the source to the app is first downloaded to your computer from the remote server. Once the application has been installed, however, there is little need to keep the archives containing the source.

cd /usr/ports/distfiles
ls

The reason why you should 'ls' is to make sure you're in the correct directory. Erasing the contents of the wrong directory could be very bad. Depending on how many Ports you've installed since the last time you cleaned out your /usr/ports/distfiles directory, your 'ls' should return something like this:

fongsaiyuk# cd /usr/ports/distfiles/
fongsaiyuk# ls
K12-1.bdf.gz                        kanji18
K12-2.bdf.gz                        kanji26
K14-1.bdf.gz                        knj10-1.1.tar.gz
K14-2.bdf.gz                        lame-3.96.1.tar.gz
Kappa20-0.396.tar.bz2               lcms-1.14.tar.gz
MPlayer-1.0pre7.tar.bz2             leafpad-0.8.1.tar.gz
Mesa-6.2.1-20050213.tar.bz2         libao-0.8.5.tar.gz
XML-Parser-2.34.tar.gz              libcroco-0.6.0.tar.bz2
aalib-1.4rc5.tar.gz                 libexif-0.6.12.tar.gz
anthy                               libgcrypt-1.2.1.tar.gz
aspell-0.60.2.tar.gz                libgpg-error-1.0.tar.gz
aspell6-en-6.0-0.tar.bz2            libiconv-1.9.2.tar.gz
aterm-0.4.2.tar.gz                  libmng-1.0.8.tar.gz
audiofile-0.2.6.tar.gz              libotf-0.9.3.tar.gz

Notice that there are a few directories (the names without extensions) as well. We can issue a single command to clean up this mess:

rm -r *

There. Do another 'ls' and you should get nothing in response. Your /usr/ports/distfiles directory has been cleaned up.

What if we want to customize our install of Mplayer (or any other Port)? No problem. To find the various compiling options available for Mplayer, simply open the Makefile in a text editor.

vi /usr/ports/multimedia/mplayer/Makefile

This will give us an idea of the options available at compile time:

# New ports collection makefile for:      mplayer
# Date created:       10 August 2001
# Whom:               Thomas E. Zander
#                     with lots of help from Vladimir Kushnir
# $FreeBSD: ports/multimedia/mplayer/Makefile,v 1.117 2005/05/17 18:01:39 pav Exp $
#
# There are many knobs to tune mplayer towards your specific wishes
# and preferences.
# You can activate a knob by typing something like
# "make -DKNOB" or "make KNOB=yes" instead of just "make"
#
# A description of the several possibilities is available here:
#
# Core funcionality:
#
# MPLAYER_GENERIC_BUILD
# default: undefined
# By default, the mplayer port creates a custom build based on personal
# preferences.
# If you want to build a generic package with certain fixed options,
# suitable for any CPU within ${ARCH}, define this knob.
# Note: The following knobs will have no effect in this case!
#
# WITH_OPTIMIZED_CFLAGS
# default: undefined
# define if you want to enable -O3 -ffast-math -fomit-frame-pointer
# on gcc build commands. This will improve speed on most machines.
#
# WITHOUT_RUNTIME_CPUDETECTION
# default: undefined
# by default, mplayer is built with support for changing the used cpu
# instruction set while playing. This is necessary for package building.
# If you want to compile a specific version of mplayer working faster
# but only on your cpu type, then define this knob.
# If you define this, there are several additional knobs to explicitly
# disable some possible CPU features. See below.
#
# WITH_NVIDIA
# default: disabled
# Enable nvidia XVMC support for nvidia video cards
# Note: This is highly experimental at the moment and works only for
#       MPEG1/2 using -vo xvmc -vc ffmpeg12mc on FreeBSD-5
#
# WITHOUT_MENCODER
# default: undefined
# the default is to build mplayer with mencoder. If you're sure that you
# don't want to encode or recode any media file, then define this.
#
# WITHOUT_X11
# default: undefined
# the default is to build mplayer with X11 support because of its capabilities
# as a video player. If you don't want to install any X11 environment and use
# mplayer as a multi-format audio-only player, this one is for you.
#
# WITH_GTK1|WITH_GTK2
# default: autodetect GTK1
# if you want mplayer to have gui abilities, you can use this knob to define
# which graphical toolkit set mplayer is built with.
# It defaults to detect and use GTK1 if it finds a working installation on the
# system. This can be overridden by choosing WITH_GTK2 or disable graphical
# user interface by defining WITHOUT_GUI
# Note: If you define WITH_GTK* *and* WITHOUT_GUI, mplayer will be built without
#       gui capabilities.
#       At the moment there is no current gtk2 patch available, so defining this
#       knob has no effect right now.
#
# WITHOUT_GUI
# default: undefined
# normally mplayer comes with gmplayer if gtk is installed on the system.
# If you want to force mplayer to disable the graphical user interface and
# build without gui ability, define this.

(Note: the Makefile in its entirety contains far more options and is much bigger than this, but these are a few sample "knobs" to give you an idea of the options available for us to define).

First of all, note that on Line 10 of the Makefile, the maintainer of this Port has been kind enough to tell us how to set any of these options at compile time: type "make KNOB=yes". In other words, if we wanted to build Mplayer without a GUI ("WITHOUT_GUI"), instead of issuing the default "make install clean" command, we would issue:

make WITHOUT_GUI=yes install clean

This will compile Mplayer without a GUI, an option that both Dan and I (Kevin) have found useful. You can set multiple options as well. For example, if you wanted to build Mplayer without a GUI and you wanted to build it in German, you would issue:

make WITHOUT_GUI=yes WITH_LANG=de install clean

Set as many options as you like in this fashion.

It is also possible to set compiling options by editing the Makefile itself. For example, if you wanted to install CUPS, we normally recommend setting three options at compile time. These can be set using the above-noted method for setting options for Mplayer, but can also be set by adding lines to the end of the Makefile itself:

vi /usr/ports/print/cups/Makefile

This will bring up a very concise file that (unfortunately) does not give us a nice list of compile options:

# ex:ts=8 -*-mode: makefile-*-
#
# New ports collection makefile for:    cups
# Date created:        2003-01-22
# Whom:                Alan Eldridge
#
# $FreeBSD: ports/print/cups/Makefile,v 1.23 2005/01/24 17:22:59 sem Exp $
#
 
PORTNAME=      cups
PORTVERSION=   ${CUPS_PORTVER}
PORTREVISION=  ${CUPS_PORTREV}
PORTEPOCH=     ${CUPS_PORTEPOCH}
CATEGORIES=    print
MASTER_SITES=  # empty
DISTFILES=     # empty
EXTRACT_ONLY=  # empty
 
MAINTAINER=    asa@agava.com
COMMENT=       The Common UNIX Printing System: Metaport to install complete system
 
LIB_DEPENDS+=  cups.2:${PORTSDIR}/print/cups-base
RUN_DEPENDS+=  espgs:${PORTSDIR}/print/cups-pstoraster \
               ${LOCALBASE}/sbin/cupsaddsmb:${PORTSDIR}/print/cups-lpr
 
.if make(package)
DEPENDS_TARGET="package"
.endif # make(package)
 
USE_PERL5=      yes
NO_BUILD=       true
 
do-patch:
       ${DO_NADA}
 
do-install:
       ${DO_NADA}
 
.include "${.CURDIR}/../../print/cups/Makefile.common"
.include
.include

Not much to look at, right? Okay, so if we were following our FreeBSD Guide instructions on Printing with CUPS, we would want to add the following 3 lines to the end of the Makefile:

CUPS_OVERWRITE_BASE=yes
NO_LPR=yes
WITH_CUPS=yes

Save changes and exit with 'ZZ', then issue our default "make install clean" instruction to compile CUPS with the 3 options we added directly to the Makefile.

But what if we wanted the same 3 options to remain set when we upgrade CUPS? No problem. Instead of (or in addition to) setting these 3 options directly in the CUPS Makefile, we can make them apply to future versions of CUPS by adding them to /etc/make.conf:

vi /etc/make.conf

This will display any compile options you set that will apply whenever applicable (i.e. any time you install a Port that recognizes them as valid options):

# added by use.perl 2005-05-20 08:38:14
PERL_VER=5.8.6
PERL_VERSION=5.8.6
COMPAT4X=true
CUPS_OVERWRITE_BASE=yes
NO_LPR=yes
WITH_CUPS=yes

See those last 3 lines? Unlike the CUPS Makefile, which will be overwritten the next time I upgrade my Ports tree, the options set in /etc/make.conf will stay there until I delete them.

Another extremely useful option to set for all Ports in this fashion is:

WANT_GNOME=no

The default option on many applications, such as The Gimp or Firefox is to enable some added Gnome-specific features. If you are using Gnome this is all well and good, but for those of us using Fluxbox or other lightweight window managers, this doesn't make a lot of sense. Setting this option in /etc/make.conf will disable this feature and save you a bunch of gnome dependencies to install.

Alternatively, you might want an option to be remembered when you upgrade one specific application, but don't want it to be applied to any application that recognizes it. A good example of this is WITHOUT_GUI. In order to preserve this option for Mplayer but nothing else, add the following lines to /etc/make.conf:

.if ${.CURDIR:M*/multimedia/mplayer}
WITHOUT_GUI=yes
.endif

This same format can be used with any application, but note that you have to specify the subdirectory within /usr/ports where your target application is located in order for this to work properly. Because Mplayer is found in /usr/ports/multimedia/mplayer, we specify .CURDIR:M*/multimedia/mplayer in the first line. If we wanted to set a specific option for vim, on the other hand, which is located in /usr/ports/editors/vim, we would specify .CURDIR:M*/editors/vim in the first line instead. Get the idea? This is an incredibly useful technique.