Converting Port Management from Ports to Pkg

Convert Ports Management from Ports to Packages on FreeBSD

The FreeBSD Ports system is very effective but costly in time to upgrade applications especially if managing a large number of servers.  With the advent of FreeBSD’s new package system – pkg and Poudriere, package management can be customized similarly to ports with the ease of upgrading via pkg.  This post demonstrates the steps require to convert a machine from utilizing ports to pkg.  If Poudriere is not desired, this guide is still applicable minus the Poudriere setups.

Install pkg if not already installed:

# /usr/sbin/pkg


Perform a query to list leaf packages:

The following query returns a list of ports which are not dependent upon any others.
# pkg query -e '%#r==0' '%n-%v: %c'
Determine which leaf ports to explicitly install and set them to non-automatic:
# pkg set -A 0 packagename packagename packagename .....

Note: ‘Automatic’ packages are removed by “pkg autoremove” when they no longer have any dependencies.  Set origin ports to ‘non-automatic’ to ensure they will not be removed when cleaning the system.

The conversion can begin when all of the origin ports are set to ‘non-automatic’.  If you are using a Poudriere setup, create a list of ‘non-automatic’ packages to add to the Poudriere repository.  Skip the following 3 steps if not using Poudriere.


Create a list of origin packages (non-automatic):

Skip this step if not using Poudriere

# pkg query -e '%a==0' '%o' > pkg-list


Add/Merge the list to the existing Poudriere list:

Skip this step if not using Poudriere.  If using Poudriere, add or merge the aforementioned “pkg-list” to the existing Poudriere list in your configuration.


Configure the machine to use the Poudriere repository:

Skip this step if not using Poudriere.  If using Poudriere, you should have the necessary information to configure the machine to utilize the Poudriere repository.


Clean up the local packages:

Delete packages which were automatically  installed as dependencies and are not required any more:
# pkg autoremove


Rebuild all packages:

Force the reinstallation or upgrade of the whole set of packages
# pkg upgrade -f

Check again for any unnecessary packages and remove them:

# pkg autoremove

All dependencies are now correctly set and the system can be managed with ‘pkg’ going forward.  If you ever need to remove an origin port going forward, you can keep your system clean with the pkg autoremove command.


Second Option:

A second option exists to have a completely clean system.  Follow the steps above to create a list of origin ports then follow the next steps.


Create backups of any modified config files and important data:

Note:  This procedure should not affect the configuration files or any other customization but it is always a good idea to create backups.


Delete all packages:

# pkg delete -a


Remove any ports that were not deleted by the previous command:

# pkg autoremove


Delete everything in /var/db/pkg:

# rm -r /var/db/pkg/*

Note: Only do this if you are sure you will be starting from scratch.


Reinstall all packages from the origin list:

# pkg install package1 package2 package3



In this post, two different options for switching port management from ports/portmaster to packages/pkg are demonstated. Using either method, ensures all dependencies are correctly set and removing unnecessary packages in the future will be more manageable.



Converting FreeBSD systems from ports to a centralized package repository

FreeBSD Forums

Leave a Reply

Your email address will not be published. Required fields are marked *