The “snap” Command in Linux [With 10+ Examples]

The “snap” command is a self-contained package used in Linux that lets you install, configure, refresh, and remove snaps. It includes all the necessary dependencies and directories for an application to run.

In this article, you will learn the characteristics and applications of the ‘snap’ command in Linux with 11 practical examples.

Syntax of “snap” Command

The basic syntax of the “snap” command is as follows:

snap <subcommand> [options] [arguments]
EXPLANATION

The <subcommand> specifies the action to be taken. The [options] are the optional flags or switches that modify the action of the specified subcommand. And, the [arguments] refers to the Snap packages on which you execute the command.

Note: For more information about snap options or run the command from your Linux terminal:

man snap

How to Install “snap” Package Manager in Linux?

You can download the snap installer and install it manually or use your Linux distribution’s package manager to download and install it. Use the below command to install the snap package manager in Linux:

Ubuntu/Debian-based:

sudo apt-get install  snapd -y

Installing the snap package manager in LinuxOr,

sudo apt-get install snapd -y

Red Hat-based (Fedora, CentOS, RHEL):

sudo dnf install -y snapd

Arch Linux:

sudo pacman -Sy snapd

Note: If you are using any other Linux distribution, follow the steps of Installing Snap in Linux to install Snap on your Linux distro.

11 Examples of Using “snap” Command in Linux

Here are a few basic and advanced practical examples of using the snap command in Linux:

1. Installing Package

To install a package using Snap, use the snap install command followed by the package name.

For example, use the below command to install Spotify:

snap install spotify

Installing Spotify using snap command

Consequently, the terminal will display a new window to get your authentication. Enter your password and click on Authenticate.Entering password for authentication

After that, Snap will start installing the package.

2. Removing Package

To remove an installed snap package from the system, use the snap remove command followed by the package name. For example, to remove spotify, use:

snap remove spotify

Removing Spotify using snap command in Linux

As a result, the installed package of Spotify is removed.

If you want to remove a specific version of a package, use –revision=[version number] before the package name in the above command. For example:

snap remove --revision=75 spotify

Removing specific version of Spotify using snap remove command

The command specifically tells the Snap package manager to remove the Spotify Snap package with revision number 75 from the system.

3. Getting Version Information of a Package

To get the revision number of any Snap package, you can use the below command:

snap list spotify

Getting revision number of snap package

Note: To remove a specific package version, you have to disable the package beforehand.

4. Update Packages to the Latest Version

To update all the installed packages to their latest versions, use the snap refresh command. You probably do not need to remember to update if you install Snapd because it automatically updates all your installed packages.

However, run the command below if you are curious to see and apply new updates to all or any particular packages:

snap refresh

Updating package to the latest version using snap refresh command

The command keeps all installed snap packages up to date with the latest features, bug fixes, and security patches in the system.

After a snap refresh, if for any reason you don’t like the new snap, use the below command to go back to the old snap:

snap revert firefox

Reverting an updated snap package

Thus, the snap package goes back to the older version.

5. Listing Installed Packages

To list all the installed snap packages in your system, use:

snap list

This command provides information such as the name, version, and developer of each snap package to view your installed snaps. It is useful when there are multiple versions of the same app in the Snap store such as Telegram.Listing all snap packages

As you can see in the above image, the command lists information on all the installed packages of the system.

6. Searching Package

To search the Snap Store for packages, use the snap find command along with the searching argument. The command lets you discover all the packages related to the searched arguments specified. However, if you search without any arguments, the command returns a list of featured snaps.

For example, to search music related packages, run the below command:

snap find music

Searching packages using snap command

The above command provides a list of available music-related applications or tools that can be installed using the Snap package manager.

7. Displaying Package Information

To get any Snap package information, you can use the snap info command along with the package name. This command shows details such as the current version, publisher, and description of any application whether it is installed or not.

For example, run the below command to get the package information for Spotify:

snap info spotify

Getting snap package information using snap info command

As you can see from the image, the command retrieves information about the Spotify snap package installed on your system.

8. Showing Package Changelog

To show a list of recent changes made to a package on your system, use the snap changes command followed by the package name. It helps you to track and understand the recent modifications of a package. Here is the command to show package changelog:

snap changes spotify

This command provides the status, summary, and time of the operation performed on Spotify in your system.Getting package changelog using snap changes command

OUTPUT ANALYSIS
  • Status: It refers to the current status of the change or operation related to the Spotify snap package. For example: Done, InProgress, Hold, Error, etc.
  • Spawn: It shows the timestamp when the change was initiated or spawned.
  • Ready: It shows whether the change is ready to be applied or has been completed.

9. Logging In/Out to Snap Store

To log in and out to the Snap store, you can use the snap command with login and logout respectively. For example, follow the steps to log in to Snap:

  1. Run the command below to initiate the authentication process for accessing the Snap Store:
    snap login

    It prompts you to the credentials (Email and Password) related to your Snap Store account.Logging in to snap store

  2. Enter your credentials to access features such as installing, updating, and managing snap packages from the Snap Store.
  3. To log out from the Snap store, run this command: snap logout

10. Displaying “snap” Command Help

To display the available commands of Snap package manager and their usage for interaction, use the snap command along with the help option:

snap help

Getting snap command description

As you can see in the above image, the snap help command shows general help information about using the Snap package manager.

11. Enabling and Disabling Package

To disable or enable the snap packages installed on the system, use snap with the enable or disable commands.

The below command disables Firefox on your system:

snap disable firefox

Disabling snap packages

To enable Firefox back, use this command:

snap enable firefox

Enabling snap packages using snap enable command

Hence, it enabled Firefox again on your system.

How to Show Permission Granted to a Snap Package?

To show permission granted to a snap package, use the snap connections command. Using this command, you can view or modify the current permission or connection of an installed Snap package.

Run the below command to view the snap permission of a package (for example: Gedit):

snap connections gedit

Viewing permission of a snap package named Gedit

This command lists the connections of the Gedit snap package, showing which interfaces it has connected to. Now, you can check which external resources or services Gedit can access through its interfaces.

To modify permissions (for example, granting or revoking access to a specific interface), use snap connect for granting permission and use snap disconnect for revoking permission.

For example, to grant network access to Gedit, use the below command:

sudo snap connect gedit:network

Granting network access to a snap package Gedit

As a result, you connect the Gedit snap package to the network interface, enabling it to access network resources.

Now, to revoke it, use the below command:

sudo snap disconnect gedit:network

Revoking snap permission to a package

Hence, the command disconnects the Gedit snap package from the network interface.

Conclusion

In this article, I’ve demonstrated the characteristics and applications with examples of the “snap” command in Linux. The corresponding “snap” commands are easy to remember if you’re used to managing software in Linux with apt.

Hopefully, you are now able to install, update, and remove packages in your Linux projects. Comment us below for any suggestions or queries.

People Also Ask

What is snap in Linux?

In Linux, the Snap refers to a package management system that allows you to package applications and dependencies into a single, self-contained package called “snap”. It provides an easy way to install, update, and manage software on Linux systems.

What is the difference between Snap and APT?

Snap and APT are both package management systems used in Linux, but they have key differences- Snap offers a modern and flexible approach to package management by providing self-contained applications that can be installed across different Linux distributions. In contrast, APT is the traditional system used for managing packages, allowing users to select specific versions for installation.

Where is Snap located in Linux?

The directory /var/lib/snapd/ contains the actual snap files. Those files will be mounted in the /snap/ root directory when the application is operating.

5/5 - (2 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
Avatar photo

Yousuf Shovon is a Linux Content Developer Executive (LCDE) at SOFTEKO. Previously, he worked for ExcelDemy, writing over 60+ articles on Excel. His goal is to write quality content for users to read and learn. In the future, he also wants to build various projects with LinuxSimply. He completed his graduation and post-graduation in Information Technology from Jahangirnagar University. Yousuf finds joy in solving diverse Linux-related problems to gain an all-around experience in Linux. Read Full Bio

Leave a Comment