FreeBSD Basic Setup and Management of Ports

You did it! You’ve successfully installed FreeBSD on your machine. Now it’s time to have some fun with ports. Ports are a way to install and manage software packages on FreeBSD. They let you customize your system with the applications you want and need. Let’s see how ports work and how to use them.

Do not worry, here we will look into ports after this, I hope you will be able to answer the following questions:

  • What are ports?
  • How to update ports?
  • How to install /uninstall software using ports?

First, let’s look into the definition of ports from the FreeBSD wiki:

The FreeBSD Ports collection is a package management system for the FreeBSD operating system. As of February 2020, there are over 38,487 ports available in the collection. It has also been adopted by NetBSD as the basis of its pkgsrc system.

Initialize Ports

Ok we are going to download and extract ports using the portsnap command

root@test:~ # portsnap auto
Looking up portsnap.FreeBSD.org mirrors... 5 mirrors found.
Fetching snapshot tag from dualstack.aws.portsnap.freebsd.org... done.
Latest snapshot on server matches what we already have.
No updates needed.
Ports tree is already up to date.
root@test:~ #

In my case there were no updates available for the ports tree, however, if is the first time you running this command it may take a few minutes to complete.

Making an alias to find a port easier

Now to make our life easier we will add an alias to the .cshrc

First, we change the directory to the root home by typing cd ~

root@test:~ # cd ~
root@test:~ # edit .cshrc

Here is a sample of .cshrc

# $FreeBSD$
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
# more examples available at /usr/share/examples/csh/
#

alias h         history 25
alias j         jobs -l
alias la        ls -aF
alias lf        ls -FA
alias ll        ls -lAF
#ports
alias cdport 'cd `whereis -q \!:1`'

As you can see, we added our alias command to the end of the of aliases.
We can exit and save changes by pressing the ESC key, and then ENTER key 2x.
Finally, we can use the new command “cdport” which will change the directory to the location of the desired port.

Installing the portmaster

 

root@test:~ # cdport portmaster
root@test:/usr/ports/ports-mgmt/portmaster # make install clean

… a few minutes later

....
====> Compressing man pages (compress-man)
===>  Installing for portmaster-3.22
===>  Checking if portmaster is already installed
===>   Registering installation for portmaster-3.22
Installing portmaster-3.22...
===>  Cleaning for portmaster-3.22

Updating all installed ports

Now let’s do an “in place” update of all ports. This will take some time depending on the CPU and RAM on your server.

root@test:/usr/ports/ports-mgmt/portmaster # cd /
root@test:/ # portmaster -a -f -D

I hope this gives you a basic understanding of ports management.