How to Update FreeBSD Ports Using Portsnap and GIT

FreeBSD's Ports Collection provides a simple and centralized way to install FreeBSD software. Ports consist of categorized directories containing makefiles that are used by the make command to compile source code into executable programs or libraries. Ports Collection is designed for automation and is relatively easy to use. With the Ports Collection, an administrator can be responsible for always updating applications/programs to the latest version sourced from the official developer who created the program.

Installing software from a port is the same as building a program from the source code. If the source code is not yet on the system, it can be downloaded from the site designated by the makefile. The system verifies the content of the downloaded source code, usually using MD5 (Message-Digest algorithm 5) hash to ensure its authenticity. An MD5 hash is a 32 character alphanumeric string that is like a fingerprint for a file. An example of writing an MD5 Hash would look like this: e6c75c12f663a484ee3157ab058cfc9e.

Once the source code is authenticated, the make program checks the makefile to see if the port requires other software. If so, FreeBSD also installs those dependencies. Next, it will be applied to the source code before being compiled and installed. After all processing is complete, ports are treated as FreeBSD packages and recorded in the installed package database, pkgdb.db, which is stored in the /var/db/pkg directory.


1. Portsnap

Portsnap is a FreeBSD utility used to take and update compressed snapshots of the FreeBSD port system, and extract and update uncompressed ports. In normal update operations, portsnap will routinely restore modified files to an unmodified state and remove unknown local files.

Before using a port, you must first get the Ports Collection directory in the /usr/ports folder. The portsnap command makes it possible to download and update the FreeBSD Ports collection via the internet. To download the Ports collection, type the following command.

root@ns2:~ # portsnap fetch
Looking up portsnap.FreeBSD.org mirrors... 5 mirrors found.
Fetching snapshot tag from dualstack.aws.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Updating from Mon Jul 3 07:05:15 WIB 2023 to Tue Jul 4 14:40:14 WIB 2023.
Fetching 5 metadata patches... done.
Applying metadata patches... done.
Fetching 0 metadata files... done.
The portsnap fetch script above is to download the Ports collection which will be extracted to the /usr/ports folder. After the download process is complete, extract portsnap with the following command.

root@ns2:~ # portsnap extract
/usr/ports/.arcconfig
/usr/ports/.gitignore
/usr/ports/.hooks/pre-commit
/usr/ports/.hooks/pre-commit.d/
/usr/ports/.hooks/prepare-commit-msg
/usr/ports/CHANGES
/usr/ports/CONTRIBUTING.md
/usr/ports/COPYRIGHT
/usr/ports/GIDs
/usr/ports/Keywords/exec.ucl
/usr/ports/Keywords/fc.ucl
Continue by updating the Ports collection.

root@ns2:~ # portsnap update
Ports tree is already up to date.


2. Update Ports With Git

Apart from portsnap, FreeBSD's Ports collection can also be updated using git.

Git is a so-called Version Control System ("VCS") that can help to keep control of a project. A project can be anything, a single shell script, a group of shell scripts, the source code for a program (or many programs) and can even update the FreeBSD kernel. To update the Ports collection with git, type the following command.

root@ns2:~ # pkg install git
root@ns2:~ #
git clone -b release/13.2.0 --depth 1 https://git.FreeBSD.org/ports.git /usr/ports
Cloning into '/usr/ports'...
Once you have finished cloning the Ports collection, run the git pull and git branch script.

root@ns2:~ # cd /usr/ports
root@ns2:/usr/ports #
git pull && git branch --all
root@ns2:/usr/ports #
git config --global --add safe.directory /usr/ports


3. Update Ports

So that the Ports collection remains and always shows the latest version, the FreeBSD Ports collection must always be updated, this is done to ensure that the applications that will be installed via the port system are the latest version. To update the Ports collection, follow the steps below.

root@ns2:~ # cd /usr/ports/lang/perl5.32
root@ns2:/usr/ports/lang/perl5.38 #
make install clean
The next step is to update the FreeBSD Ports collection with portmaster. Type the following command.

root@ns2:~ # cd /usr/ports/ports-mgmt/portmaster
root@ns2:/usr/ports/ports-mgmt/portmaster #
make install clean
The portmaster will identify four categories of ports:
Root Port: The root port has no dependents and no dependencies.
Trunk Port: Trunk Port has no dependents, but is dependent on other ports.
Branch port: Branch Port has dependencies and depends on other ports.
Leaf port: Leaf Port has dependencies but does not depend on any other port.

Portmaster is only installed once. To make updates to Portmaster or update Portmaster, you only need to type the following command.

root@ns2:~ # portmaster -L
To renew or update all old ports, use the following script.

root@ns2:~ # portmaster -a
We can also add -f to upgrade and rebuild all ports if problems occur during the upgrade process.

root@ns2:~ # portmaster -af
Portmaster can also be used to install new ports, updating all dependencies before building and installing the new port. To use this feature, specify the port location in the Ports Collection. The example below is for updating bash program dependencies.

root@ns2:~ # portmaster shells/bash
The next step to update the Ports collection is with the portupgrade command.

root@ns2:~ # cd /usr/ports/ports-mgmt/portupgrade
root@ns2:/usr/ports/ports-mgmt/portupgrade #
make install clean
Use the following command to update all existing ports on the FreeBSD system.

root@ns2:~ # portupgrade -a
Alternatively, add -i to require confirmation of each ports update.

root@ns2:~ # portupgrade -ai
To update only one application, use the following script.

root@ns2:~ # portupgrade -R apache24
or
root@ns2:~ #
portupgrade -PP apache24
4. Cleaning Ports Garbage

Using Ports Collection will take up disk space. After the application is installed and updated, it will leave a cache file in the Ports collection. Running make clean inside the port framework will remove the temporary working directory. Unless -K is given, Portmaster automatically destroys this directory after installing and updating applications. Example, If apache24 is installed, the following command will remove all temporary files from the local copy of the Ports Collection.

root@ns2:~ # cd /usr/ports/www/apache24
root@ns2:/usr/ports/www/apache24 #
make install clean
root@ns2:/usr/ports/www/apache24 #
portsclean -C
The first script in the command above opens the /usr/ports/www/apache24 folder, the second script installs the apache24 application and the third script will delete the temporary dependency files used to install apache24. This file is usually in the work folder. During the Apache installation process, the work folder is in the /usr/ports/www/apache24/work folder.

Apart from that, the distribution files that come from the installation source are gathered in the /usr/ports/distfiles folder. To remove all distfiles that are no longer referenced by any ports use Portupgrade. But it is recommended that files in the /usr/ports/distfiles folder not be deleted. Run the following command to delete files in the /usr/ports/distfiles folder.

root@ns2:~ # portsclean -D
or
root@ns2:~ #
portscleaning -DD
Apart from installing applications using ports, FreeBSD also provides a utility for installing ports, namely pkg. With pkg, program/application installation can take place quickly. The discussion about pkg will be explained in the next article.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post