How to Uninstall Packages and Clean Dependencies on FreeBSD
pkg
tool and the legacy Ports Collection.Categories:
3 minute read
FreeBSD is a powerful and flexible UNIX-like operating system that offers extensive package management capabilities. Over time, as software is installed and removed, unused dependencies can accumulate, consuming unnecessary disk space and potentially impacting system performance. This guide explores how to properly uninstall packages and clean up dependencies on FreeBSD using both the traditional pkg
tool and the legacy Ports Collection.
Understanding FreeBSD Package Management
FreeBSD provides two primary methods for managing software:
- Binary Packages (
pkg
) – A modern package management system that allows users to install, upgrade, and remove precompiled software. - Ports Collection – A more customizable method that allows users to compile software from source with specific options.
Both methods require periodic maintenance to keep the system lean and efficient.
Uninstalling Packages with pkg
The pkg
tool simplifies package management, including removal. To uninstall a package, use:
pkg delete package_name
For example, to remove vim
:
pkg delete vim
Removing Packages and Their Unused Dependencies
By default, pkg delete
does not remove dependencies that are no longer needed. To remove a package along with its unused dependencies, use:
pkg autoremove
This command scans the system for orphaned dependencies (libraries or programs no longer required by any installed package) and removes them.
Cleaning Up Leftover Files
Even after removing a package, some configuration files and logs might remain. To check for residual files:
pkg info -l package_name
If any files remain, manually delete them using:
rm -rf /path/to/file_or_directory
Additionally, FreeBSD maintains package metadata in /var/db/pkg/
. If you encounter inconsistencies, you can clean up the package database with:
pkg check -d
Uninstalling Ports and Cleaning Dependencies
For users who install software via the Ports Collection, uninstallation requires the make deinstall
command:
cd /usr/ports/category/portname
make deinstall
For instance, to remove vim
installed from Ports:
cd /usr/ports/editors/vim
make deinstall
Removing Unused Dependencies from Ports
To clean up dependencies installed via Ports that are no longer needed:
pkg autoremove
Additionally, the portmaster
utility can be used for thorough cleaning:
portmaster --clean-distfiles
To remove orphaned ports:
portmaster --check-depends
Cleaning Distfiles and Temporary Files
When compiling software from source using Ports, downloaded source tarballs accumulate in /usr/ports/distfiles/
, consuming disk space. To remove them:
rm -rf /usr/ports/distfiles/*
Alternatively, use:
portsclean -D
To remove outdated or unnecessary files related to installed ports:
portsclean -C
Checking for Orphaned Libraries
Over time, shared libraries may become orphaned when packages are removed. To identify orphaned libraries:
ldd /usr/local/bin/* | grep 'not found'
To remove unused libraries:
pkg autoremove
or manually delete unreferenced libraries from /usr/local/lib/
.
Keeping the System Clean and Updated
Regular maintenance prevents clutter and improves system efficiency. Here are some best practices:
Periodically remove unnecessary packages:
pkg delete package_name
Regularly clean up dependencies:
pkg autoremove
Delete outdated distfiles:
portsclean -D
Check for orphaned files and libraries:
pkg check -d
Conclusion
Managing installed packages and cleaning dependencies on FreeBSD is essential for maintaining system efficiency. By using pkg
, the Ports Collection, and additional cleanup tools like portmaster
and portsclean
, you can ensure that your system remains lean and clutter-free. Regular maintenance not only conserves disk space but also helps avoid potential conflicts and performance issues.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.