FreeBSD provides various tools as a part of its base system. In FreeBSD, there are two ways to install software packages from official repositories or third-party sources i.e. pkg and ports. The pkg is used to install from prebuilt binaries and port is used to install from sources.
I already discussed how to install or remove packages using pkg. This article is on installing and removing a software package using ports collection in FreeBSD.
The ports collection
Ports collection in FreeBSD offers a simple way to compile and install third-party applications. It is also used to build packages that are to be installed using pkg. The packages compiled and installed using port collection is known as ports. Port collection can be installed and updated using portsnap. By default, it gets stored as the subdirectory of /usr/ports
.
It does not come preinstalled so first you need to install it in your system. Use the following commands to download the ports collection in compressed form –
portsnap fetch
Now extract the ports collection files using-
portsnap extract
And finally, update it –
portsnap update
How to install a package using the ports collection
To install a package using the ports collection, first, you need to change the directory to the port that is to be installed. For example to install nano text editor in your system, Use the given sequence of commands in your terminal –
First, check the subdirectories under the ports directory –
ls /usr/ports
The text editor nano will come under editors, now move into this directory by using the given command –
cd /usr/ports/editors
Now if you run the following command and scroll down you will see a directory with the name nano –
ls | more
Move into the nano directory –
cd nano
Now use the following command to install nano text editor –
make install
This will start compiling and it can prompt you for compile-time options. You can select or deselect them as per your need. Now you can check the installed application by running it –
nano
Clean the temporary files
During the installation process, a working directory is created which contains all the temporary files used during the compilation. You can remove this directory and can save some space on your disk. Also, it minimizes the problems later when upgrading the application to a newer version.
Now use the following command to remove it –
make clean
How to remove the installed ports
You can remove the installed ports using the deinstall command, first, you need to move to the ports directory. To remove nano from your system use-
cd /usr/ports/editors/nano
And then run –
make deinstall
Alternatively, you can use the pkg command to remove an installed package –
pkg delete nano
Ok, that’s all for now. If you have something to say on this topic then write to us in the comments below.