In this guide, we are going to learn how to install or uninstall software on FreeBSD 12 using Ports Collection. Ports Collection is is a set of
Makefiles, patches, and description files which are used to compile and install an individual application on FreeBSD. An application/software being compiled is called a port.
Install or Uninstall Software on FreeBSD 12 using Ports Collection
To install or uninstall a software using Ports collections, you first need to install Ports Collection if at all they were not installed with the OS.
Install Ports Collection using Portsnap on FreeBSD 12
The recommended way of installing Ports Collection on FreeBSD is to use Portsnap. Portsnap is a fast and user-friendly tool for retrieving the Ports Collection. It connects to a FreeBSD site, verifies the secure key, and downloads a new copy of the Ports Collection.
To begin with, run system update and upgrade
pkg upgrade -f
download a compressed snapshot of the Ports Collection. The snapshot will be stored under /var/db/portsnap.
Looking up portsnap.FreeBSD.org mirrors... 6 mirrors found. Fetching public key from ec2-ap-southeast-2.portsnap.freebsd.org... done. Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org... done. Fetching snapshot metadata... done. Fetching snapshot generated at Fri Jun 21 03:03:21 EAT 2019: be72cc6990cd51c776b41c1a4e848af2b5516e4667ccc8 84 MB 126 kBps 11m20s Extracting snapshot... done. Verifying snapshot integrity... done. Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org... done. Fetching snapshot metadata... done. Updating from Fri Jun 21 03:03:21 EAT 2019 to Fri Jun 21 15:32:36 EAT 2019. Fetching 5 metadata patches... done. Applying metadata patches... done. Fetching 0 metadata files... done. Fetching 51 patches. (51/51) 100.00% done. done. Applying patches... done. Fetching 0 new ports or files... done.
Once the fetching completes, extract Ports Collection snapshot to /usr/ports. This can only be done if the snapshot was being fetched for the first time.
If the Ports Collection snapshot has been downloaded before, you can simply update it by running the commands below;
portsnap fetch portsnap update
You can however run this as a single command;
portsnap fetch update
Installing Software using Ports Collection
Before you can compile a software/application, here in called a port, ensure that you have GNU make (gmake)utility installed. To verify if gmake is installed;
which gmake /usr/local/bin/gmake
Installing GNU make utility
If gmake is not installed, see below on how to install.
pkg install gmake
Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 1 package(s) will be affected (of 0 checked): New packages to be INSTALLED: gmake: 4.2.1_3 Number of packages to be installed: 1 The process will require 2 MiB more space. 382 KiB to be downloaded. Proceed with this action? [y/N]: y [1/1] Fetching gmake-4.2.1_3.txz: 100% 382 KiB 390.7kB/s 00:01 Checking integrity... done (0 conflicting) [1/1] Installing gmake-4.2.1_3... [1/1] Extracting gmake-4.2.1_3: 100%
Next, navigate to the specific sub-directory of the software/port to be installed. For example, in this guide, we are going to demonstrate how to install neofetch, command-line tool for fetching system information.
Next, compile the port or software as shown below;
===> Building/installing dialog4ports as it is required for the config dialog ===> Cleaning for dialog4ports-0.1.6 ===> License BSD2CLAUSE accepted by the user ===> dialog4ports-0.1.6 depends on file: /usr/local/sbin/pkg - found => dialog4ports-0.1.6.tar.gz doesn't seem to exist in /usr/ports/distfiles/. => Attempting to fetch http://files.etoilebsd.net/dialog4ports/dialog4ports-0.1.6.tar.gz dialog4ports-0.1.6.tar.gz 10 kB 5073 kBps 00s ===> Fetching all distfiles required by dialog4ports-0.1.6 for building ===> Extracting for dialog4ports-0.1.6 => SHA256 Checksum OK for dialog4ports-0.1.6.tar.gz. ===> Patching for dialog4ports-0.1.6 ===> Configuring for dialog4ports-0.1.6 ===> Building for dialog4ports-0.1.6 cc -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -Wall -pedantic -c dialog4ports.c -o dialog4ports.o cc -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -Wall -pedantic -c mixedlist.c -o mixedlist.o gzip -cn dialog4ports.1 > dialog4ports.1.gz cc -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -Wall -pedantic dialog4ports.o mixedlist.o -o dialog4ports -lncursesw -lm -ldialog ===> Staging for dialog4ports-0.1.6 ===> Generating temporary packing list install -s -m 555 dialog4ports /usr/ports/ports-mgmt/dialog4ports/work/stage/usr/local/bin install -m 0644 dialog4ports.1.gz /usr/ports/ports-mgmt/dialog4ports/work/stage/usr/local/man/man1 ====> Compressing man pages (compress-man) ===> Installing for dialog4ports-0.1.6 ===> Checking if dialog4ports is already installed ... ====> Compressing man pages (compress-man) ===> Installing for bash-5.0.7 ===> Checking if bash is already installed ===> Registering installation for bash-5.0.7 as automatic Installing bash-5.0.7... ===> neofetch-6.0.0 depends on executable: bash - found ===> Returning to build of neofetch-6.0.0 ===> Generating temporary packing list install -m 0644 /usr/ports/sysutils/neofetch/work/neofetch-6.0.0/CHANGELOG.md /usr/ports/sysutils/neofetch/work/stage/usr/local/share/doc/neofetch install -m 0644 /usr/ports/sysutils/neofetch/work/neofetch-6.0.0/README.md /usr/ports/sysutils/neofetch/work/stage/usr/local/share/doc/neofetch ====> Compressing man pages (compress-man) ===> Installing for neofetch-6.0.0 ===> Checking if neofetch is already installed ===> Registering installation for neofetch-6.0.0 Installing neofetch-6.0.0...
Neofetch is now installed.
which neofetch /usr/local/bin/neofetch
``` ` [email protected] ` `.....---.......--.``` -/ -------------------------- +o .--` /y:` +. OS: FreeBSD 12.0-RELEASE amd64 yo`:. :o `+- Uptime: 2 hours, 15 mins y/ -/` -o/ Packages: 134 (pkg) .- ::/sy+:. Shell: csh tcsh 6.20.00 / `-- / Terminal: /dev/pts/0 `: :` CPU: Intel i5-8250U (1) @ 1.800GHz `: :` GPU: VirtualBox Graphics Adapter / / Memory: 334MiB / 985MiB .- -. -- -. `:` `:` .-- `--. .---.....----.
After the installation, run make clean to remove temporary files that were created during the installation to save space.
You can also check how to install MySQL 8 on FreeBSD 12 as another example.
Uninstalling Software using Ports Collection
To uninstall any software or port installed via the Ports Collection on FreeBSD 12, simply navigate to the port subdirectory and run make deinstall. For example, to remove neofetch installed above;
===> Deinstalling for neofetch ===> Deinstalling neofetch-6.0.0 Updating database digests format: 100% Checking integrity... done (0 conflicting) Deinstallation has been requested for the following 1 packages (of 0 packages in the universe): Installed packages to be REMOVED: neofetch-6.0.0 Number of packages to be removed: 1 [1/1] Deinstalling neofetch-6.0.0... [1/1] Deleting files for neofetch-6.0.0: 100%
Well, that is all on how to install and uninstall software on FreeBSD 12 using Ports collection.