Coming from a Linux or Windows background, many people begin to wonder where to get and how to install applications on FreeBSD. Well, with FreeBSD most applications can be installed from the Internet so you don’t have to find the tarballs. There are two different installation methods to choose from and they both do a great job dealing with dependancies.
- Local root access on the box or be able to su to root.
- A SSH client that supports ANSI colors such as puTTy or SecureCRT (if you aren’t on the box).
- Internet Access.
The ports tree is a collection of useful programs that have been ported to FreeBSD. These are not the binary packages, but the source to compile from. The advantage of ports is that you can compile a program tailored to your system, as apposed to somebody else’s.
When users first install FreeBSD, many of them forget to install the ports tree. This is probably because they are new to the system and didn’t know what the ports tree was. Install the ports tree if you haven’t yet.
Select Configure -> Distributions -> Ports. Select OK and then the installation media you wish to use. I used the installation CD. Once your ports tree is installed, exit sysinstall and portsnap your tree to make sure it’s up-to-date.
The ports tree is located at /usr/ports and it is organized by category/port. For instance, you will find Apache2 located in /usr/ports/www/apache2. If you know what you want to install but you don’t know where it’s located in the ports tree, you can issue:
cd /usr/ports make search name=port name
For example, say I want to install nmap but I don’t know where it’s at. All I have to do is the following:
# cd /usr/ports # make search name=nmap Port: nmap-3.75 Path: /usr/ports/security/nmap Info: Port scanning utility for large networks Maint: eik at FreeBSD dot org B-deps: openssl-0.9.7e_1 pcre-5.0 R-deps: openssl-0.9.7e_1 pcre-5.0 Port: nmapfe-3.75 Path: /usr/ports/security/nmapfe Info: GUI frontend for the nmap scanning utility Maint: eik at FreeBSD dot org B-deps: XFree86-libraries-4.4.0_2 expat-1.95.8 fontconfig-2.2.3,1 freetype2-2.1.7_3 gettext-0.13.1_1 glib-1.2.10_11 gtk-1.2.10_12 imake-4.4.0 libiconv-1.9.2_1 perl-5.6.1_15 pkgconfig-0.15.0_1 R-deps: XFree86-libraries-4.4.0_2 expat-1.95.8 fontconfig-2.2.3,1 freetype2-2.1.7_3 gettext-0.13.1_1 glib-1.2.10_11 gtk-1.2.10_12 imake-4.4.0 libiconv-1.9.2_1 nmap-3.75 openssl-0.9.7e_1 pcre-5.0 perl-5.6.1_15 pkgconfig-0.15.0_1
Ah, there it is in /usr/ports/security/nmap and now I can install it. Once you know what you want to install and where it’s located, let’s install it.
cd /usr/ports/security/nmap make install clean
make simply compiles the program from source. install tells make to install the package after it’s compiled. Finally, clean tells make to clean up after itself as it creates files and directories during the compiling process. If there are missing dependancies, make will also grab and install them.
Note: An alternate is to run make install distclean that will delete the downloaded tarball located in /usr/ports/distfiles after it cleans up. This is to save your disk space.
Note: You can compile various ports with additional configuration options so it is a good idea to read the Makefile before you install the port.
That’s all there is to it. You will see a lot of compiling text scroll by and eventually your command prompt will return to you. At that time, you will know your package was installed and is ready to be used.
Now you can just as easily uninstall your application, say nmap, using the ports tree.
cd /usr/ports/security/nmap make deinstall clean
nmap is now removed from your system.
FreeBSD packages are the binary versions of the ports. This means somebody precompiled the application and so the installation goes by a lot quicker. There is no waiting for it to compile on your own system — it just gets installed. This also means you cannot add or remove any special compiling options for the package, such as qmail.
Installation and removal is quite simple. To install a package, say nmap, and grab the tarball from the Internet you would just issue:
pkg_add -r nmap
The -r tells pkg_add to grab nmap from a remote location. It will do just that: grab the tarball from a remote site, unpackage it, and install it. If there are any missing dependancies, pkg_add will grab those as well.
Now, if you are wanting to uninstall a package you once installed, say nmap, you will have to issue:
Note: You must specify the package with the version number as it appears in pkg_info(1) otherwise it will not be removed.
That’s all there is to it. Pick a method and start installing your favorite applications. I personally like using the ports tree over packages because there is more control with that method. But, it’s a personal preference.