Apt Command in Ubuntu
Apt Command in Ubuntu: Want to install a specific version of a package in Ubuntu? You can do that ‘easily’ in the following manner:
sudo apt install package_name=package_version
How do you know which versions are available for a certain package? Use this command:
apt list –all-versions package_name
In the screenshot below, you can see that I have two versions of VLC available and I use the command to install the older version:
25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management
Sounds like a simple task, right? But things are not as simple as they look. There are several ifs and buts involved here.
This tutorial will cover all the important aspects of installing a specific program version using apt or apt-get commands.
Things to know about installing a specific version of a program
You need to know a few things about how APT and repositories work in Ubuntu and Debian-based distributions.
No older versions from the same source
Ubuntu doesn’t keep older versions of packages in the repository. You may see more than one version in specific cases, temporarily. For example, you run the apt update (but not upgrade), and a new version is available. You may see two versions for the same package in the apt-cache. But as soon as the package is upgraded to the new version, the older version is removed from the cache as well as the repositories.
Use multiple sources for different versions
To get multiple versions of the same package, you’ll have to add multiple sources. For example, VLC is in version 3. x. Adding the VLC daily build PPA will give the (unstable) version 4. x.
Similarly, you can download a DEB file with a different version and install it.
The higher version always gets the priority
If you have the same package available from more than one source, by default, Ubuntu will install the highest available version.
In the previous example, if I install VLC, it will install version 4. x, not 3. x.
The older version gets upgraded to the available newer version
That’s another potential problem. Even if you install the older version of a package, it gets upgraded to the newer version (if available). You have to hold the package and stop it from upgrading.
Dependencies also need to be installed
If the package has dependencies, you’ll have to install the required version of the dependent packages as well.
Now that you know a few potential issues let’s see how to tackle them.
Installing a specific version of a package
I am taking the example of VLC in this tutorial. VLC version 3.0.16 is available in Ubuntu’s repositories. I added the daily build PPA and that gives me the release candidate of VLC version 4.0.
As you can see, I have two VLC versions available in the system right now:
abhishek@itsfoss:~$ apt list -a vlc
vlc/jammy 4.0.0~rc1~~git20220516+r92284+296~ubuntu22.04.1 amd64
vlc/jammy 3.0.16-1build7 amd64
vlc/jammy 3.0.16-1build7 i386
Since the higher version takes priority, using ‘apt install vlc’ will result in the installation of VLC 4.0. But I want to install the older version 3.0.16 for the sake of this tutorial.
sudo apt install vlc=3.0.16-1build7
But here’s the thing. The vlc package has several dependencies and those dependencies also need specific versions. However, Ubuntu tries to install the available higher versions for them, and thus, you get the classic ‘you have held broken packages‘ error.
To fix this, you have to provide specific versions of all the dependent packages it complains about. So that command becomes something like this:
sudo apt install vlc=3.0.16-1build7 \
apt Command in Linux
In case you are wondering, the trailing \ at the end of each line is just a way to write a single command over multiple lines.
Does it work? In many cases, it will. But I have chosen a complicated example of VLC, which has lots of dependencies. Even the mentioned dependencies have dependencies on other packages. It gets messy.
An alternative is to specify the source while installing.
Alternatively, specify the repository source
You have added multiple sources, so you should have some idea about the sources the package comes from.
Use the command below and search for the repository:
apt-cache policy | less
Focus on the lines that come after the repository name:
500 http://security.ubuntu.com/ubuntu jammy-security/multiverse i386 Packages
apt Command Examples for Ubuntu/Debian Linux
You can specify the o,l,a, etc parameters.
In my original example, I want to install VLC from Ubuntu’s repository (to get 3.16) instead of the PPA (which gives me 4).
So the command below will install VLC 3.16 along with all the dependencies:
sudo apt install -t “o=ubuntu” vlc
Looks good? But the problem comes when you have to update the system. Then it complains about not finding the specified version.
What else can be done?
To install an older version, remove the source of the newer version from your system (if possible). It helps get rid of the dependencies hell issues.
If that’s not possible, check if you can get it in some other packaging formats like Snap, Flatpak, AppImage, etc. In fact, Snap and Flatpak also allow you to choose and install from available versions. Since the applications are sandboxed, it’s easier to manage the dependencies for different versions.
Hold the package and prevent upgrade
If you manage to install a specific program version, you may want to avoid accidentally upgrading to the newer version. It’s not too complicated to achieve this.
sudo apt-mark hold package_name
You can remove the hold so that it can be upgraded later:
sudo apt-mark unhold package_name
Note that dependencies of a package are not automatically held. They need to be individually mentioned.
As you can see, there is a provision to install the selected version of a program. Things only get complicated if the package has dependencies. Then you get into the dependency hell.
I hope you learned a few new things in this tutorial. If you have questions or suggestions to improve it, please let me know in the comment section.
https://linuxize.com › post › how-to-use-apt-command
24-Feb-2020 — apt is a command-line utility for installing, updating, removing, and otherwise managing deb packages on Ubuntu, Debian, and related Linux …
https://www.cyberciti.biz › Howto › Debian / Ubuntu
27-Apr-2022 — APT stands for Advanced Package Tool. It is a set of core tools inside Debian and Ubuntu Linux system. You can use the apt command to …
Description: Advanced Package Tool
OS compatibility: Debian • Mint • Ubuntu
https://www.tecmint.com › useful-basic-commands-of-a…
13-Mar-2013 — The apt-cache command line tool is used for searching apt software package cache. In simple words, this tool is used to search software packages
https://www.linuxtechi.com › apt-command-ubuntu-de…
09-Jan-2022 — Apt is a command line package management utility for Ubuntu and Debian Linux. Apt is used to install, remove, update and upgrade Debian
https://www.geeksforgeeks.org › apt-get-command-in-li…
04-Apr-2019 — apt-get is a command-line tool which helps in handling packages in Linux. Its main task is to retrieve the information and packages from the
https://guide.ubuntu-fr.org › server › apt
The apt command is a powerful command-line tool, which works with Ubuntu’s Advanced Packaging Tool (APT) performing such functions as installation of new
https://codeburst.io › a-beginners-guide-to-using-apt-ge…
18-Mar-2018 — APT(Advanced Package Tool) is a command line tool that is used for easy interaction with the dpkg packaging system and it is the most efficient
https://www.computerhope.com › Help › Linux
01-Feb-2021 — On Linux operating systems that use the APT package management system, the apt command installs, removes, upgrades, and manages software …
List: List packages that meet a certain set of crit…
Update: The update command downloads up-t…
Install pkg: Installs the package named pkg. The …
Full-upgrade: Perform an upgrade, but also re…
https://phoenixnap.com › Home › SysAdmin
In Linux, special tools were developed for managing applications. Application software for Linux typically comes in a package. The default package manager for
- https://phoenixnap.com › Home › SysAdmin
- 25-Jun-2020 — Prior to Ubuntu 16.04, users regularly interacted with the APT package manager through the use of command line tools: apt-get, apt-cache,
https://www.digitalocean.com › community › tutorials
06-Aug-2013 — Apt is a command line frontend for the dpkg packaging system and is the preferred way of managing software from the command line for many
https://geekflare.com › Geekflare Articles
20-Jul-2021 — APT or Advanced Package Tool is the Command Line utility for package management in Debian/Ubuntu-based distributions.
https://www.maketecheasier.com › Linux
25-Oct-2021 — What Distros Use APT? · Debian · Ubuntu · Linux Mint · MX Linux · Grml · Kali Linux · Tails · PureOS
https://linux.die.net › man › apt-get
apt-get is the command-line tool for handling packages, and may be considered the user’s “back-end” to other tools using the APT library.
https://www.linuxtoday.com › developer › 15-apt-com
10-Jan-2022 — Apt is a command-line package management utility for Ubuntu and Debian Linux. Apt is used to install, remove, update and upgrade Debian
https://www.stechies.com › Windows › Windows Tutorial
The APT (Advanced Package Tools) is a package manager used for managing packages of Debian-based operating systems and its derivatives, such as Ubuntu.
https://vitux.com › how-to-use-apt-get-package-manage
19-Jul-2021 — How to use apt Package Manager on Ubuntu Command Line · Update the Package Repositories with apt · Update Installed Software with apt · Search for …