1. Overview

In Linux distributions, a package is a compressed archive containing all the essential files for a specific software or application. These files include the executable binary, libraries, configuration files, and many other resources.

We may need to install the latest or a specific version of a package for several reasons, such as to get the new software or an application on the system, manage dependencies, or keep the system up to date. Thus, according to the Linux distribution, we can download the desired packages to the system using various package managers, such as apt, yum, dnf, snap, or flatpak.

In this tutorial, we’ll discuss how to install a specific version of a package using Snap on the Ubuntu 22.04 Linux system.

2. Introduction to Snap

Snap is a popular package manager that allows users to install and manage Snaps, i.e., applications and software packages on various Linux distributions. It streamlines the software management process by installing packages and their dependencies in a single package. We can use it to efficiently install new packages and update or remove existing packages on the Linux system.

3. Advantages of Snap Over Other Package Managers

Snap offers several advantages over other package managers, i.e., apt, yum, etc., in Linux distribution:

  • Snap is a cross-distribution package manager, meaning its packages can run across numerous Linux distributions, such as Ubuntu, Debian, Fedora, and Arch Linux
  • It provides a sandboxed environment that enhances security by isolating applications and packages from the rest of the system
  • It can automatically update Snaps to the latest version to ensure that users always have the latest features and security fixes
  • Snap packages also include all the dependencies required to run the application

4. Installing Packages Using Snap

We can install various packages or applications using the Snap package manager. It enables us to install the latest or particular package version on the Snap Store.

4.1. Install snapd

First, we install snapd (snap demon), which is a background service used to manage snap packages on the Linux system:

$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  snapd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
...

Let’s now check the installed snapd version for verification:

$ snap version
snap    2.63
snapd   2.63
series  16
ubuntu  22.04
kernel  6.5.0-35-generic

The snapd is installed successfully.

4.2. Find the Package’s Available Versions

We can check all the available versions of a specific package and choose any desired version to install on the system.

For instance, let’s check the available versions of docker using the snap info command:

$ snap info docker
name:      docker
summary:   Docker container runtime
publisher: Canonical✓
store-url: https://snapcraft.io/docker
contact:   https://github.com/docker-snap/docker-snap/issues?q=
license:   (Apache-2.0 AND MIT AND GPL-2.0)
description: |
  Build and run container images with Docker.
. . .
 
services:
  docker.dockerd:                  simple, enabled, inactive
  docker.nvidia-container-toolkit: oneshot, enabled, inactive
snap-id:      sLCsFAO8PKM5Z0fAKNszUOX0YASjQfeZ
tracking:     latest/beta
refresh-date: 14 days ago, at 01:55 PKT
channels:
  latest/stable:    24.0.5   2024-02-01 (2915) 136MB -
  latest/candidate: 24.0.5   2024-02-01 (2915) 136MB -
  latest/beta:      24.0.5   2023-10-30 (2915) 136MB -
  latest/edge:      24.0.5   2024-04-24 (2925) 138MB -
  core18/stable:    20.10.17 2023-03-13 (2746) 146MB -
  core18/candidate: ↑                                
  core18/beta:      ↑                                
  core18/edge:      ↑                    

Thus, the output shows detailed information about the docker package, including all the available versions, such as latest/stable, latest/candidate, latest/beta, core18/stable, etc.

4.3. Install the Latest Version of the Package

To install the latest version of a specific package available on the Snap store, we use the snap install command along with the desired package name.

Let’s install the latest version of docker using the snap package manager:

$ sudo snap install docker
docker 24.0.5 from Canonical✓ installed

We have successfully installed the latest version of docker, i.e., 24.0.5.

4.4. Install the Specific Version of the Package

We can also install a specific version of any package by specifying the required version using the –channel option. We can specify a different channel, e.g., stable, candidate, beta, or edge, from which to fetch the package.

For example, we install the core18/stable version of the docker package:

$ sudo snap install docker --channel=core18/stable
docker (core18/stable) 20.10.17 from Canonical✓ installed

As a result, the required docker version, i.e., core18/stable 20.10.17, is installed successfully on the system.

4.5. Verify Installation

Finally, use the snap list command to display the installed package of docker for verification:

$ snap list docker
Name    Version   Rev   Tracking       Publisher   Notes
docker  20.10.17  2746  core18/stable  canonical✓  -

Hence, we get the output that displays details about the installed Docker package, including the Name, Version, Rev (revision), Publisher, etc.

5. Upgrading and Downgrading Snap Packages

If a specific version of a package is already installed on the system, we can either upgrade or downgrade it to get the required version.

5.1. Upgrade Package to the Specific Version

To upgrade a snap package to the specific required version, we use the snap refresh command and specify the package name with its desired version.

For instance, let’s upgrade the existing docker package to the latest/beta version:

$ sudo snap refresh docker --channel=latest/beta
docker (beta) 24.0.5 from Canonical✓ refreshed

Subsequently, the docker package is upgraded to the beta 24.0.5 version.

5.2. Downgrade Package to the Specific Version

If we didn’t like the updated version of the installed package for any reason, we can use the snap revert command to revert it to the previously installed version.

Let’s revert the docker package to its previously installed version:

$ sudo snap revert docker
docker reverted to 20.10.17

As a result, the docker package is successfully reverted to the 20.10.17 version.

6. Removing Snap Packages

We can also remove the snap packages if we no longer need them. We use the snap remove command with the package name that needs to be deleted to remove it from the system.

Let’s remove the docker package from the system:

$ sudo snap remove docker
2024-06-04T01:06:47+05:00 INFO Waiting for "snap.docker.dockerd.service" to stop.
docker removed

Thus, the docker package is successfully removed.

7. Conclusion

In this article, we explained how to install a specific package version using the Snap package manager. We used the snap install command along with the desired package name and –channel option to get the required package’s version.

We also discussed several advantages of using Snap over traditional package managers, the method for installing Snapd, finding available Snap packages, and upgrading, downgrading, and removing packages in a Linux system.