FreeBSD operating system can use binary packages with pkg utility, but for for some ocassion, like running newest versions of the code, you would want to compile some programs. For that, there is very useful ports collection that simplifies compilation process. In this article we will install and use ports collection to update the Freebsd 11.0 system. This article assumes you have installed FreeBSD 11 using our previous article.
Using port collection to install portmaster
If you are using ssh to access your FreeBSD machine, you would want to get root for your regular user before proceeding, because you access the VM as user and then you need to use su. By default, FreeBSD will give you sorry message, and to avoid that, use following command:
pw user mod username -G wheel
Next we can move to getting the ports tree from online repostory:
portsnap fetch extract
This command will will get and extract snap of entire ports collection on your FreeBSD system. Next time you want to use ports, you wont need to fetch and extract, instead just run
portsnap fetch update
Next we need to change working directory to application that we want to install, which in this case is portmaster
And then simply type
make install clean
And the ports will do the magic. It will compile install a portmaster, a shell script that helps update of all ports.
Updating ports with portmaster
So we have installed first program from source code using ports collection. Next command we will run will show us what ports are ready for update:
pkg version -l '<'
Note that in older versions of FreeBSD, there was pkg_version command, as of 10.0 it was changed to pkg version.
Output should be something like this:
atril-1.12.2 < bash-4.3.46_1 < ca_root_nss-3.26 < expat-2.1.1_2 < galculator-2.1.3 < glib-2.46.2 < hal-0.5.14_30 < harfbuzz-1.3.0 < icu-55.1 < indexinfo-0.2.4 < iso-codes-3.65 < libassuan-2.4.2 < libgd-2.2.2,1 < libgpg-error-1.23 < libmateweather-1.12.1 < librsvg2-2.40.13 < libspectre-0.2.7_2 < libtasn1-4.8 < llvm37-3.7.1_2 <
To see possible issues with packages that are ready to upgrade, you need to type
Like with previous command, there there was underline in previous versions, now it is gone. Sample output of the command:
pkg updating 20160907: AFFECTS: users of math/galculator AUTHOR: woodsb02@FreeBSD.org galculator now uses GTK3 by default. An option exists in the port to revert to GTK2 if desired. 20160311: AFFECTS: print/cups-base, print/cups-client, print/cups-image AUTHOR: tijl@FreeBSD.org The cups-base, cups-client and cups-image packages have been combined into one cups package. If you build your own ports the easiest way to update is to delete these packages first and then build and install print/cups. If you are using binary packages, depending on the packages installed on your system, pkg(8)'s solver might get confused. In this case do not proceed with the upgrade but delete first the packages: pkg delete -fg "cups*" Then usual upgrade process: pkg upgrade ......
After you decide that updating is safe for your system, you can run following command to recompile and install all packages that are ready to update
Compile will most probably take a long time. So get some snack, or go for a walk until it finishes.
Searching, installing and removing ports
After update have been finished, lets see how we can find and install additional software using ports. If you know the name of the package you are looking for, you can type its name preceded with "whereis". For example
It will direct you to directory where skeleton of nginx is, and from there you can install it. But if you don't know the exact name of package, you can use the the ports search feature. For that you would need to cd to ports directory first
cd /usr/ports/ make search name=nginx
It will output all the packages that are related to nginx.
Now that you know how to find package, you install it, same like we installed portmaster on start of this article. First cd into skeleton directory:
Then start the process of compilation
make install clean
It will give you configuration options in ncurses environment like this:
We will just accept defaults and continue. It will install and compile nginx. And if you now again type whereis, it will give you different output:
whereis nginx nginx: /usr/local/sbin/nginx /usr/local/man/man8/nginx.8.gz /usr/ports/www/nginx
It gives you the binary path, the man page path and in the end the port skeleton.
To remove the port just go to skeleton and type deinstall. Like this:
cd /usr/ports/www/nginx make deinstall
We gone trough the basic usage of FreeBSD ports collection, with updating, installing, searching, and deinstalling ports. Ports are the feature of FreeBSD that have inspired Linux distribution Gentoo in making portage package manager to mimic the FreeBSD ports. Ports have many more features that we couldn't possibly cover in single article. We encourage you to explore. Thanks for reading, this is all for this article.