apt-get Install Specific Version | Linux Package Guide

Software package with version labels and selection tools symbolizing the apt-get install specific version command

The ability to install specific versions of packages has come in handy while managing servers at IOFLOOD. Drawing from our expertise and processes, we have crafted today’s article to address the question of how to install a specific version of a package using ‘apt-get’. Our hope is to provide a helpful resource for our dedicated hosting customers and fellow developers who wish to enhance their package management and server depoloyment efficiency.

This guide will walk you through the steps to install a specific version of a package using apt-get, from basic use to advanced techniques. We’ll explore apt-get’s core functionality, delve into its advanced features, and even discuss common issues and their solutions.

So, let’s dive in and start mastering apt-get!

TL;DR: How Do I Install a Specific Version of a Package Using apt-get?

To install a specific version of a package using apt-get, you use the following command: sudo apt-get install =. This command allows you to specify the package and the version you want to install.

Here’s a simple example:

sudo apt-get install curl=7.58.0-2ubuntu3.8

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# curl is already the newest version (7.58.0-2ubuntu3.8).
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

In this example, we’re using the apt-get install command to install a specific version of the curl package. The version is specified after the equals sign. The output confirms that the specified version of curl is already installed.

This is a basic way to use apt-get install to install a specific version of a package, but there’s much more to learn about managing packages in Linux with apt-get. Continue reading for more detailed information and advanced usage scenarios.

The Basics of apt-get install

The apt-get install command is a fundamental tool for any Linux user. It’s a part of the Advanced Packaging Tool (APT) system, which is a set of core libraries and a command-line utility designed to handle packages in Linux. The apt-get install command allows you to install any available version of a software package.

To specify a version, you append an equals sign and the version number to the package name. Here’s the general syntax:

sudo apt-get install <package>=<version>

Let’s see this in action with a real-world example:

sudo apt-get install apache2=2.4.29-1ubuntu4.14

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
#   apache2-data
# Suggested packages:
#   www-browser apache2-doc apache2-suexec-pristine | apache2-suexec-custom
# The following NEW packages will be installed:
#   apache2 apache2-data
# 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
# Need to get 1,358 kB of archives.
# After this operation, 5,537 kB of additional disk space will be used.
# Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2-data all 2.4.29-1ubuntu4.14 [159 kB]
# Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.14 [1,199 kB]
# Fetched 1,358 kB in 1s (1,013 kB/s)
# Selecting previously unselected package apache2-data.
# (Reading database ... 145480 files and directories currently installed.)
# Preparing to unpack .../apache2-data_2.4.29-1ubuntu4.14_all.deb ...
# Unpacking apache2-data (2.4.29-1ubuntu4.14) ...
# Selecting previously unselected package apache2.
# Preparing to unpack .../apache2_2.4.29-1ubuntu4.14_amd64.deb ...
# Unpacking apache2 (2.4.29-1ubuntu4.14) ...
# Setting up apache2-data (2.4.29-1ubuntu4.14) ...
# Setting up apache2 (2.4.29-1ubuntu4.14) ...
# Enabling module mpm_event.
# Enabling module authz_core.
# Enabling module authz_host.
# Enabling module authn_core.
# Enabling module auth_basic.
# Enabling module access_compat.
# Enabling module authn_file.
# Enabling module authz_user.
# Enabling module alias.
# Enabling module dir.
# Enabling module autoindex.
# Enabling module env.
# Enabling module mime.
# Enabling module negotiation.
# Enabling module setenvif.
# Enabling module filter.
# Enabling module deflate.
# Enabling module status.
# Enabling module reqtimeout.
# Enabling conf charset.
# Enabling conf localized-error-pages.
# Enabling conf other-vhosts-access-log.
# Enabling conf security.
# Enabling conf serve-cgi-bin.
# Enabling site 000-default.
# Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
# Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
# Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
# Processing triggers for systemd (237-3ubuntu10.44) ...
# Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
# Processing triggers for libc-bin (2.27-3ubuntu1.2) ...

In this example, we’re using apt-get install to install a specific version of the Apache2 package. The output confirms that the specified version of Apache2 is installed, and it also lists the additional packages that were installed as dependencies.

While apt-get install is a powerful command, it’s essential to be careful when specifying versions. Installing an older version of a package may break dependencies with other packages, leading to software instability. Therefore, it’s always recommended to understand the implications and make sure the specific version you’re installing is compatible with your system.

Dependency Management Techniques

When installing specific versions of packages using apt-get install, you may encounter dependency issues. These occur when the version you’re trying to install requires a different version of another package than the one currently installed on your system. In such cases, apt-get will attempt to resolve these dependencies, but it can sometimes lead to conflicts.

To illustrate this, let’s try to install a version of a package that has dependencies:

sudo apt-get install libssl1.0.0=1.0.2n-1ubuntu5.6

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# Some packages could not be installed. This may mean that you have
# requested an impossible situation or if you are using the unstable
# distribution that some required packages have not yet been created
# or been moved out of Incoming.
# The following information may help to resolve the situation:
#
# The following packages have unmet dependencies:
#  libssl1.0.0 : Depends: libc6 (>= 2.14) but 2.27-3ubuntu1 is to be installed
# E: Unable to correct problems, you have held broken packages.

In this example, the libssl1.0.0 package requires a different version of libc6 than the one installed on the system. As a result, apt-get is unable to install the specified version of libssl1.0.0.

To resolve such issues, you may need to install the required version of the dependent packages manually or use a package manager that can handle complex dependencies automatically.

Another advanced use of apt-get install is to install multiple specific versions of packages at once. This can be done by specifying each package and its version, separated by a space:

sudo apt-get install curl=7.58.0-2ubuntu3.8 libssl1.0.0=1.0.2n-1ubuntu5.6

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# curl is already the newest version (7.58.0-2ubuntu3.8).
# Some packages could not be installed. This may mean that you have
# requested an impossible situation or if you are using the unstable
# distribution that some required packages have not yet been created
# or been moved out of Incoming.
# The following information may help to resolve the situation:
#
# The following packages have unmet dependencies:
#  libssl1.0.0 : Depends: libc6 (>= 2.14) but 2.27-3ubuntu1 is to be installed
# E: Unable to correct problems, you have held broken packages.

In this example, we’re trying to install specific versions of both curl and libssl1.0.0. However, due to the dependency issue with libssl1.0.0, the command fails.

When using apt-get install to handle specific versions, it’s important to understand the dependencies between packages and how to manage them. It’s also crucial to know that while you can install multiple specific versions at once, the command will fail if any of the packages have unmet dependencies.

Alternative Methods: Yum and Zypper

While apt-get is a powerful tool for managing packages in Linux, it’s not the only one. Other package managers like yum and zypper also offer the ability to install specific versions of packages. These alternatives might be more suitable depending on your system’s distribution or your personal preferences.

Installing Specific Versions with Yum

Yum (Yellowdog Updater, Modified) is the default package manager for Red Hat-based distributions. Like apt-get, yum allows you to install specific versions of packages. Here’s the general syntax:

sudo yum install <package>-<version>

Here’s an example of installing a specific version of the httpd package using yum:

sudo yum install httpd-2.4.6-90.el7.centos

# Output:
# Loaded plugins: fastestmirror
# Loading mirror speeds from cached hostfile
#  * base: mirror.umd.edu
#  * extras: mirror.umd.edu
#  * updates: mirror.umd.edu
# Resolving Dependencies
# --> Running transaction check
# ---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
# --> Finished Dependency Resolution
#
# Dependencies Resolved
#
# ================================================================================
#  Package       Arch            Version                        Repository     Size
# ================================================================================
# Installing:
#  httpd         x86_64          2.4.6-90.el7.centos           base          2.7 M
#
# Transaction Summary
# ================================================================================
# Install  1 Package
#
# Total download size: 2.7 M
# Installed size: 9.4 M
# Is this ok [y/d/N]: y
# Downloading packages:
# httpd-2.4.6-90.el7.centos.x86_64.rpm                              | 2.7 MB  00:00:01
# Running transaction check
# Running transaction test
# Transaction test succeeded
# Running transaction
#   Installing : httpd-2.4.6-90.el7.centos.x86_64                                  1/1
#   Verifying  : httpd-2.4.6-90.el7.centos.x86_64                                  1/1
#
# Installed:
#   httpd.x86_64 0:2.4.6-90.el7.centos
#
# Complete!

In this example, we’re using yum install to install a specific version of the httpd package. The output confirms that the specified version of httpd is installed.

Installing Specific Versions with Zypper

Zypper is the default package manager for openSUSE distributions. Like apt-get and yum, zypper can also install specific versions of packages. Here’s the general syntax:

sudo zypper install <package>-<version>

Here’s an example of installing a specific version of the apache2 package using zypper:

sudo zypper install apache2-2.4.23-8.1.x86_64

# Output:
# Loading repository data...
# Reading installed packages...
# Resolving package dependencies...
#
# The following NEW package is going to be installed:
#   apache2
#
# 1 new package to install.
# Overall download size: 1.1 MiB. Already cached: 0 B. After the operation, additional 3.4 MiB will be used.
# Continue? [y/n/...? shows all options] (y): y
# Retrieving package apache2-2.4.23-8.1.x86_64
#                                                     (1/1), 1.1 MiB (  3.4 MiB unpacked)
# Retrieving: apache2-2.4.23-8.1.x86_64.rpm ...................................................[done]
# Checking for file conflicts: ........................................................................[done]
# (1/1) Installing: apache2-2.4.23-8.1.x86_64 ....................................................[done]

In this example, we’re using zypper install to install a specific version of the apache2 package. The output confirms that the specified version of apache2 is installed.

These examples illustrate that while apt-get is a powerful tool for installing specific versions of packages in Linux, there are other package managers like yum and zypper that offer similar functionality. Depending on your system’s distribution and your personal preferences, these alternatives might be more suitable.

Common Issues with apt-get install

While using apt-get install to install specific versions of packages, you may encounter some common issues. One of the most frequent issues is the ‘E: Version ‘…’ for ‘…’ was not found’ error. This error occurs when the specified version of the package is not available in your configured repositories.

Resolving ‘E: Version ‘…’ for ‘…’ was not found’ Error

Let’s see an example of this error and how to resolve it:

sudo apt-get install curl=7.58.0-2ubuntu3.9

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# E: Version '7.58.0-2ubuntu3.9' for 'curl' was not found

In this example, we’re trying to install version 7.58.0-2ubuntu3.9 of the curl package, which doesn’t exist in the repositories configured on our system. As a result, apt-get throws an error.

To resolve this issue, you can use the apt-cache policy command to list the available versions of the package in your repositories:

apt-cache policy curl

# Output:
# curl:
#   Installed: 7.58.0-2ubuntu3.8
#   Candidate: 7.58.0-2ubuntu3.8
#   Version table:
#  *** 7.58.0-2ubuntu3.8 500
#         500 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
#         100 /var/lib/dpkg/status
#      7.58.0-2ubuntu3 500
#         500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages

In this output, you can see the available versions of the curl package. You can then choose a version from this list to install.

By understanding the common issues you may encounter while using apt-get install for specific versions and knowing how to resolve them, you can ensure a smooth and efficient package management process.

Package Management Fundamentals

apt-get is a powerful command-line tool used in Debian and Ubuntu-based Linux distributions for handling packages. It stands for ‘Advanced Package Tool’, and as the name suggests, it allows users to interact with the software packages of their system. It uses a repository of available packages and their versions to install, upgrade, or remove software on a Linux system.

sudo apt-get update

# Output:
# Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
# Get:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
# Get:3 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
# Get:4 http://archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
# Fetched 252 kB in 1s (185 kB/s)
# Reading package lists... Done

In this example, we’re using apt-get update to update the package lists for upgrades and new package installations. This command is typically used before installing or upgrading packages to ensure you’re getting the latest versions available.

Understanding Version Management

Linux distributions manage software versions using repositories. A repository is a storage location from which software packages are retrieved and installed on a system. Each Linux distribution has its own set of repositories that contain all the software packages and their versions that the distribution supports.

When you use apt-get install to install a specific version of a package, apt-get checks the repositories for the specified version and installs it. If the version is not found in any of the repositories, apt-get will return an error.

You can check the versions of a package available in your repositories using the apt-cache policy command:

apt-cache policy curl

# Output:
# curl:
#   Installed: 7.58.0-2ubuntu3.8
#   Candidate: 7.58.0-2ubuntu3.8
#   Version table:
#  *** 7.58.0-2ubuntu3.8 500
#         500 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
#         100 /var/lib/dpkg/status
#      7.58.0-2ubuntu3 500
#         500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages

In this example, we’re using apt-cache policy to check the available versions of the curl package in our repositories. The output shows the installed version, the candidate version (the version that would be installed if you ran apt-get install curl without specifying a version), and a table of all available versions.

Understanding the fundamentals of the apt-get command and how versions are managed in Linux distributions is crucial to effectively using apt-get install for specific versions.

Relevance of Specific Versioning

The ability to install specific versions of software packages is not just a neat trick; it’s a vital skill for system administrators and software developers. In system administration, you may need to maintain legacy systems that rely on older versions of software packages. In software development, you might be developing against a specific version of a library or framework.

As such, understanding how to use apt-get install to install specific versions is an essential part of managing a Linux system. It gives you the control to decide which versions of software packages your system runs, allowing you to manage dependencies, mitigate security risks, and maintain compatibility.

Further Info: Package Management

The world in Linux doesn’t stop at installing specific versions. There are many related concepts that are worth exploring, such as software repositories and package dependencies.

Software repositories are storage locations from which software packages are retrieved and installed on a system. Each Linux distribution has its own set of repositories that contain all the software packages and their versions that the distribution supports. Understanding how repositories work can help you manage your system more effectively.

Package dependencies are another crucial aspect of package management. When you install a software package, it might depend on other packages to function correctly. These dependencies can become complex, especially when dealing with specific versions. Understanding how dependencies work can help you resolve issues and ensure the stability of your system.

Further Resources for Mastering apt-get install

For those who want to delve deeper into the intricacies of apt-get install and package management in Linux, here are some resources to explore:

Recap: apt-get and Specific Versions

In this comprehensive guide, we’ve delved into the detailed usage of apt-get install to install specific versions of packages in Linux. We’ve explored the command’s core functionality, advanced features, and solutions to common issues, providing a thorough understanding of this powerful tool for package management in Linux.

We began with the basics, learning how to use apt-get install to install specific versions of packages. We then dove into more advanced usage, discussing how to handle dependencies and install multiple versions at once. We also looked at common issues that you might encounter when using apt-get install for specific versions, such as ‘E: Version ‘…’ for ‘…’ was not found’ error, and provided solutions to these problems.

Along the way, we explored alternative approaches to installing specific versions, introducing other package managers like yum and zypper. Here’s a quick comparison of these methods:

MethodProsCons
apt-getPowerful, widely used in Debian-based distrosMay require troubleshooting for some packages
yumDefault in Red Hat-based distros, similar functionalityDifferent syntax, not used in Debian-based distros
zypperDefault in openSUSE, similar functionalityDifferent syntax, not used in Debian-based distros

Whether you’re a system administrator maintaining legacy systems, a developer working against specific versions of libraries, or a Linux enthusiast looking to understand more about your system, we hope this guide has provided you with a deeper understanding of how to use apt-get install to install specific versions of packages in Linux.

Mastering apt-get install for specific versions equips you with greater control over your system, allowing you to manage dependencies, mitigate security risks, and maintain compatibility. Happy package managing!