Apt install specific version

Today, I want to talk about Debian-based Linux distributions focusing on “apt install specific version”
Let me explain in details.

## How to Use `apt` to Install a Specific Version of a Package

The Advanced Package Tool (`apt`) is a powerful package management tool used in Debian-based Linux distributions like Ubuntu. By default, `apt` installs the latest available version of a package from the repositories. However, there may be situations where you need to install a specific version of a package, either for compatibility reasons or to avoid breaking dependencies. This article explains how to use `apt` to install a specific version of a package step by step.

—

### **Why Install a Specific Version? via apt**
There are several scenarios where installing a specific version of a package becomes necessary:
– **Software Compatibility**: Some applications or projects require a specific version of a library or package.
– **Bug Avoidance**: A newer version of a package may introduce bugs or compatibility issues.
– **Legacy Systems**: Older systems may depend on specific versions of software.

—

### **Step-by-Step Guide to Installing a Specific Version Using `apt`**

1. **Update the Package Lists**
Before installing any package, update your package lists to ensure you have the latest information about available versions in your repositories.

“`bash
sudo apt update
“`

2. **Search for Available Versions**
To find the specific version of a package, use the `apt-cache policy` command. For example, to see the available versions of `nginx`:

“`bash
apt-cache policy nginx
“`

The output will display the versions available in the repositories, similar to this:

“`
nginx:
Installed: (none)
Candidate: 1.20.2-1ubuntu2
Version table:
1.21.6-1~ubuntu 500
1.20.2-1ubuntu2 500
“`

– **Installed**: The currently installed version (if any).
– **Candidate**: The version that would be installed by default.
– **Version Table**: A list of all available versions, along with their priorities.

3. **Install the Specific Version**
Once you identify the version you need, you can install it by specifying the package name and version in the following format:

“`bash
sudo apt install package-name=version
“`

For example, to install version `1.20.2-1ubuntu2` of `nginx`, run:

“`bash
sudo apt install nginx=1.20.2-1ubuntu2
“`

Ensure that you match the version string exactly as it appears in the `apt-cache policy` output.

4. **Hold the Package at the Specific Version (Optional)**
If you don’t want the package to be upgraded during a system update, you can put the package on hold:

“`bash
sudo apt-mark hold package-name
“`

For example:

“`bash
sudo apt-mark hold nginx
“`

To unhold the package and allow updates, use:

“`bash
sudo apt-mark unhold package-name
“`

5. **Verify the Installed Version**
After installation, you can verify the installed version using the `apt-cache policy` command again:

“`bash
apt-cache policy package-name
“`

For example:

“`bash
apt-cache policy nginx
“`

The output should now show the specific version you installed as the “Installed” version.

—

## **Apt install specific version: Common Issues and Solutions**

1. **Version Not Found**
If the specific version is not available, it could be due to:
– Outdated repository data: Run `sudo apt update` to refresh the package lists.
– The version is not in the currently enabled repositories. You may need to enable additional repositories or download the package manually.

2. **Dependency Conflicts**
Sometimes, installing a specific version may lead to dependency issues. In such cases:
– Try to resolve the dependency manually by installing the required versions of other packages.
– Consider using tools like `aptitude`, which can provide alternative solutions to resolve dependencies.

Example:

“`bash
sudo aptitude install package-name=version
“`

3. **Pinned Packages**
If a version is pinned to a lower priority, you might need to override the pinning temporarily:

“`bash
sudo apt install package-name=version –allow-downgrades
“`

—

## **Tips for Managing Specific Package Versions via apt**

– **Check Changelogs**: Before downgrading or locking a version, review the changelog to understand the differences between versions.
– **Backup Your System**: Always create a system snapshot or backup before making significant changes to installed packages.
– **Use Virtual Environments**: For libraries or programming tools, consider using tools like `virtualenv` or `conda` to isolate dependencies.

—

#### **Apt install specific version: Therefore…**
Using `apt` to install a specific version of a package is a straightforward process, but it requires attention to detail, especially when dealing with dependencies. By following the steps outlined in this guide, you can confidently install and manage specific package versions on your Debian-based Linux system. Always remember to test changes in a safe environment before applying them to production systems.

Leave a Comment