How to Exclude Packages from Updates on FreeBSD Operating System
Categories:
7 minute read
FreeBSD is a powerful and versatile Unix-like operating system known for its robustness, performance, and advanced features. It is widely used in servers, despaces, and embedded systems. One of the key strengths of FreeBSD is its package management system, which allows users to easily install, update, and manage software packages. However, there are scenarios where you might want to exclude certain packages from being updated. This could be due to compatibility issues, the need to maintain a specific version for software development, or simply to avoid potential disruptions caused by updates.
In this article, we will explore various methods to exclude packages from updates on FreeBSD. We will cover both the pkg
package management tool and manual methods to achieve this. By the end of this article, you should have a clear understanding of how to manage package updates effectively on FreeBSD.
Understanding FreeBSD Package Management
Before diving into the specifics of excluding packages from updates, it’s important to understand how package management works on FreeBSD. FreeBSD uses the pkg
tool for package management, which is a modern replacement for the older pkg_*
tools. The pkg
tool provides a simple and efficient way to manage software packages, including installation, removal, and updating.
Key Features of pkg
- Binary Package Management:
pkg
allows you to install pre-compiled binary packages, which are faster to install compared to building from source. - Dependency Resolution:
pkg
automatically resolves and installs dependencies for packages. - Version Management: You can install specific versions of packages and manage updates.
- Package Database:
pkg
maintains a database of installed packages, making it easy to query and manage them.
Updating Packages on FreeBSD
To update all installed packages on FreeBSD, you can use the following command:
sudo pkg upgrade
This command will check for updates for all installed packages and install the latest versions. However, as mentioned earlier, there are situations where you might want to exclude certain packages from being updated.
Methods to Exclude Packages from Updates
There are several methods to exclude packages from updates on FreeBSD. We will discuss the most common and effective methods below.
1. Using pkg lock
to Prevent Package Updates
The pkg lock
command is a straightforward way to prevent specific packages from being updated. When you lock a package, it will not be upgraded or modified by the pkg upgrade
command.
Steps to Lock a Package
Lock a Package: To lock a package, use the following command:
sudo pkg lock <package_name>
Replace
<package_name>
with the name of the package you want to lock. For example, to lock thenginx
package, you would run:sudo pkg lock nginx
Verify the Lock: You can verify that a package is locked by running:
pkg lock -l
This command will list all locked packages.
Unlock a Package: If you later decide to allow updates for the package, you can unlock it using:
sudo pkg unlock <package_name>
For example, to unlock the
nginx
package:sudo pkg unlock nginx
Advantages of Using pkg lock
- Simple and Effective: The
pkg lock
command is easy to use and provides a quick way to prevent updates for specific packages. - Persistent: The lock persists across reboots and package upgrades.
Limitations
- Manual Management: You need to manually lock and unlock packages as needed.
- No Granular Control: The lock applies to the entire package, so you cannot lock specific versions or components of a package.
2. Using pkg.conf
to Exclude Packages
Another method to exclude packages from updates is by modifying the pkg.conf
configuration file. This file contains various settings for the pkg
tool, including options to exclude packages from upgrades.
Steps to Exclude Packages Using pkg.conf
Edit
pkg.conf
: Open thepkg.conf
file in a text editor. The file is typically located at/usr/local/etc/pkg.conf
.sudo vi /usr/local/etc/pkg.conf
Add Exclude Directive: Add the following line to the file to exclude specific packages:
PKG_EXCLUDE: <package_name1> <package_name2> ...
Replace
<package_name1>
,<package_name2>
, etc., with the names of the packages you want to exclude. For example, to excludenginx
andphp74
, you would add:PKG_EXCLUDE: nginx php74
Save and Exit: Save the changes and exit the text editor.
Verify the Configuration: You can verify that the packages are excluded by running:
pkg upgrade -n
The
-n
flag performs a dry run, showing what would be upgraded without actually performing the upgrade. Check the output to ensure that the excluded packages are not listed.
Advantages of Using pkg.conf
- Centralized Configuration: The
pkg.conf
file provides a centralized location to manage package exclusions. - Persistent: The exclusions persist across reboots and package upgrades.
Limitations
- Manual Editing: You need to manually edit the configuration file, which may not be as convenient as using the
pkg lock
command. - No Granular Control: Similar to
pkg lock
, this method applies to the entire package and does not allow for version-specific exclusions.
3. Using pkg version
to Hold Specific Versions
If you want to hold a specific version of a package and prevent it from being upgraded, you can use the pkg version
command. This method is useful when you need to maintain a specific version of a package for compatibility or testing purposes.
Steps to Hold a Specific Version
Check Installed Versions: First, check the currently installed versions of packages using:
pkg version -v
This command will list all installed packages along with their versions.
Hold a Specific Version: To hold a specific version of a package, you can use the
pkg set
command. For example, to hold thenginx-1.18.0
package, you would run:sudo pkg set -o www/nginx:nginx-1.18.0
This command tells
pkg
to hold the specified version of the package.Verify the Hold: You can verify that the package is held by running:
pkg version -v
The held package should be marked as
held
in the output.Release the Hold: If you later decide to allow updates for the package, you can release the hold using:
sudo pkg set -r www/nginx
This command removes the hold on the package, allowing it to be upgraded.
Advantages of Using pkg version
- Version-Specific Control: This method allows you to hold specific versions of packages, providing more granular control compared to
pkg lock
orpkg.conf
. - Flexible: You can easily hold or release specific versions as needed.
Limitations
- Manual Management: You need to manually manage the holds, which can be cumbersome if you have many packages to manage.
- Complexity: This method requires a deeper understanding of package versions and may not be as straightforward as other methods.
4. Using pkg-static
for Manual Package Management
In some cases, you may want to manually manage package updates without relying on the pkg
tool’s automated features. FreeBSD provides the pkg-static
command, which is a statically linked version of the pkg
tool that can be used to manually install, upgrade, or remove packages.
Steps to Manually Manage Packages
Install
pkg-static
: Ifpkg-static
is not already installed, you can install it using:sudo pkg install pkg-static
Manually Upgrade Packages: To manually upgrade specific packages, you can use the
pkg-static install
command. For example, to upgrade thenginx
package, you would run:sudo pkg-static install nginx
This command will upgrade the
nginx
package to the latest version available in the repository.Exclude Packages: To exclude specific packages from being upgraded, you can simply avoid running the
pkg-static install
command for those packages. This method requires manual intervention and is not as automated as other methods.
Advantages of Using pkg-static
- Full Control: Manual package management gives you full control over which packages are upgraded and when.
- Flexibility: You can choose to upgrade or exclude packages on a case-by-case basis.
Limitations
- Time-Consuming: Manual package management can be time-consuming, especially if you have many packages to manage.
- Error-Prone: Manually managing packages increases the risk of human error, such as forgetting to upgrade critical packages.
Conclusion
Excluding packages from updates on FreeBSD can be necessary for various reasons, such as maintaining compatibility, avoiding disruptions, or preserving specific versions for development purposes. FreeBSD provides several methods to achieve this, including using the pkg lock
command, modifying the pkg.conf
file, holding specific versions with pkg version
, and manually managing packages with pkg-static
.
Each method has its advantages and limitations, and the choice of method depends on your specific needs and preferences. For most users, the pkg lock
command and pkg.conf
file provide a simple and effective way to exclude packages from updates. However, if you need more granular control over package versions, the pkg version
command and manual package management with pkg-static
offer additional flexibility.
By understanding and utilizing these methods, you can effectively manage package updates on FreeBSD and ensure that your system remains stable and reliable. Whether you’re a system administrator, developer, or advanced user, these techniques will help you maintain control over your FreeBSD environment.
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.