Snap Package: The Ultimate Guide
Tired of the endless software installation struggles?
Most users, including system administrators and developers, face the challenge of dependency conflicts and system compatibility issues when installing new applications on a Linux system.
Canonical, the company behind Ubuntu provides a universal solution for this challenge — Snap packages.
Snap packages, or Snaps, are a modern software packaging system that includes all the dependencies and libraries required to run an application, ensuring compatibility and reducing conflicts.
In this tutorial, we will discuss everything you need to know about Snap packages.
What Are Snap Packages?
Snap is a modern software packaging and deployment system that includes various applications and all their dependencies, libraries, and binaries.
Unlike traditional package managers, Snaps include all libraries and dependencies required to run an application. This eliminates the common issues of dependency hell and software conflicts that can arise when installing third-party software.
Snap packages offer a streamlined and efficient approach to software management on Linux systems with features like automatic updates, versioning, and enhanced security through sandboxing.
The Key Features of Snap Packages
The following are some of the key features of Snap packages that make it an ideal choice for system administrators and developers.
Universal Compatibility
Snaps are adaptable and can run on most Linux distributions, including Ubuntu, Fedora, Debian, and Arch Linux. Snap packages are built to provide a consistent experience across different systems and distributions.
Isolation and Security
Snap packages are sandboxed, meaning they run in isolation from the rest of the system. This design choice significantly enhances security by minimizing potential damage from compromised applications.
Automatic Updates
Snaps can be set to update automatically, ensuring that users always have the latest features and security patches without manual intervention.
Versioning
Multiple versions of the same application can be installed simultaneously, allowing users to switch between versions easily.
Ease of Use
Installing, updating, and removing Snap packages is straightforward and can be done with simple commands, making software management user-friendly.
Now that you know what the Snap package is, let us see how to install and manage it. However, before we move on, let us quickly examine the prerequisites.
The Prerequisites
Before you dive into the installation and use cases, ensure you have the following.
- Terminal or command line access
- A user account with sudo or administrative privileges.
How to Install snapd
snapd is the daemon that manages Snap packages on your system. To get started with using Snap packages, you’ll need to install snapd first.
Given the popularity of Snap packages, most modern Linux distributions come with snapd pre-installed. So, you should start by checking if your system already has snapd installed by executing the following command:
# snap version
If snapd is installed, you’ll see its version information. If not, follow the instructions below for your specific distribution:
For Ubuntu and Debian-based distributions, execute the following command:
# sudo apt update
# sudo apt install snapd
Note: On older Ubuntu versions, you might need to create a symbolic link for the snap command using the following command: sudo ln -s /var/lib/snapd/snap /usr/bin/snap
For Fedora-based distributions, run the following command:
# sudo dnf install snapd
Now that you have installed snapd, let us discuss how to manage Snap packages.
How to Manage Snap Packages
Managing Snap packages is crucial for several reasons including system organization, performance optimization, and resource control.
Snap packages can be managed in two primary methods:
- Via the command line/ terminal
- Utilize the graphical Snap Store app.
Let us discuss each in detail.
Method #1: Via Command Line or Terminal
The command line offers precision and flexibility for managing Snap packages on the Linux system.
To install Snap packages via the command line, execute the following command:
# snap install package_name
Replace <package-name> with the desired package name. For instance, run the following command to install the VLC Media Player:
# snap install vlc
Method #2: Utilize Snap Store GUI App
If you prefer a user-friendly graphical user interface (GUI), use the Snap Store app that provides a visual way to manage Snap packages.
If the Snap Store app is not already installed, you can install it by executing the following command:
# sudo snap install snap-store
Next, to install an app from the Snap Store app, search for Snap Store in your applications menu or run snap-store in the terminal.
Find desired packages using the search bar.
Click Install on the package’s page and enter your password when prompted. Wait for the download and installation to complete.
Install and Manage Packages Through the Command Line and GUI
Here are some examples of how to install an application using the command line and the Snap Store GUI.
Example #1: Install VLC Media Player
To install the VLC media player using the terminal or command line method, execute the following command:
# sudo snap install vlc
Next, verify the installation by executing the following command:
# snap list | grep vlc
Now, if you want to install a VLC media player using Snap Store, search for Snap Store in your applications menu or run snap-store in the terminal.
Type VLC in the search bar and click on it.
Click Install and enter your password when prompted.
Example #2: Update All Snap Packages
If you want to update your Snap packages via the command-line method, open the terminal and execute the following command:
# sudo snap refresh
Alternatively, if you want to update it using the Snap Store then open Snap Store.
Go to the Installed tab and click on the Refresh button.
The Snap Store will check for updates to all installed Snap packages and prompt you to install them.
Example #3: Remove a Snap Package
Uninstalling a package is just as important as installing it.
We will use the VLC application we installed earlier to demonstrate how to remove a Snap package using the command line. For this, open the terminal window and run the following command:
# sudo snap remove vlc
Alternatively, if you want to remove it using Snap Store, navigate to the Installed tab.
Locate the VLC package in the list of installed applications and click it to open its details page.
Click the Remove button to uninstall VLC.
Example #4: Find Available Snap Packages
If you want to find a specific Snap package, you can either use the command line or the Snap Store.
If you prefer the command line method, then open the terminal and execute the following command:
# snap find <search-term>
Replace <search-term> with the desired application. For instance, to search Media Player application, run:
# snap find media player
Alternatively, if you want to find using the Snap Store, follow the steps below:
Enter snap-store in the terminal or find it in your applications menu.
Use the search bar at the top of the screen to enter your search term.
The Snap Store displays a list of available Snap packages matching your search.
Example #5: View Snap Package Information
You can either use the command line or Snap Store to view Snap Package information.
If you wish to use the command line, open the terminal and execute the following command to view information:
# snap info <package-name>
Replace <package-name> with the name of the Snap package you want to inspect.
For instance, to view information on VLC, run:
# snap info vlc
Alternatively, if you are using Snap Store, open the Snap Store application.
Search for the desired Snap package and click on the package to view its details page, which provides information about the package, including version, publisher, and description.
Advanced Snap Package Management
Advanced Snap Package management consists of more sophisticated techniques and tools for handling Snap packages beyond basic package installation and removal.
Let us discuss some of the advanced Snap package management techniques.
Feature #1: Downgrade Snaps
Snaps maintain multiple revisions, allowing users to revert to older versions if needed. This process is known as downgrading a package.
If you want to downgrade Snap using the terminal, open the terminal window and execute the following command:
# snap info <package-name>
This command displays information about the Snap, including available revisions.
For instance, to list available revisions of the VLC, run:
# snap info vlc
Alternatively, if you want to downgrade to a specific version of a package, execute the following command:
# sudo snap revert <package-name> — revision=<revision-number>
Replace <package-name> with the Snap’s name and <revision-number> with the desired revision.
For instance, to downgrade VLC to version 1700, run:
# sudo snap revert vlc — revision=1700
Caution: Downgrading might introduce compatibility issues. Use it carefully.
Feature #2: Enable/Disable Snaps
If you want to control a Snap, you can either enable or disable it.
To enable a Snap, execute the following command:
# sudo snap enable <package-name>
This allows the Snap to start automatically when the system boots.
For instance, to enable VLC, run:
# sudo snap enable vlc
To disable a snap, execute the following command:
# sudo snap disable <package-name>
This prevents the Snap from starting automatically.
For instance, to disable VLC:
# sudo snap disable vlc
Feature #3: List All Running Services
Many Snaps include background services that are essential for their functionality. To list all the services running, open the terminal and execute the following command:
# snap services
This command displays a list of all running Snap services and their status.
If you want to start, restart, and stop services, execute the following appropriate commands:
To start a Snap service, execute the following command:
# sudo snap start <service-name>
For instance, to start the VLC service, run the following command:
# sudo snap start vlc
To restart a Snap service, execute the following command:
# sudo snap restart <service-name>
If you want to stop a Snap service, run the following command:
# sudo snap stop <service-name>
By understanding these advanced features, you can effectively manage your Snap packages and services to meet your specific needs.
Offline Snap Package Management
Managing Snap packages offline is a useful feature that provides flexibility and control when internet access is limited. It plays a crucial role in setting up secure environments with restricted internet access and deploying applications in remote locations.
Follow the steps below to download Snap packages for offline installation.
Open the terminal and download the desired Snap package by executing the following command:
# snap download <package-name>
For instance, to download VLC, execute the following command:
# snap download vlc
This command downloads the Snap package and the associated assert file to the current directory:
- <package-name>.snap: The actual Snap package containing the application.
- <package-name>.assert: The file verifying the package’s integrity.
Next, transfer both the .snap and .assert files to the target machine where you will install the Snap package. This can be done using a USB drive, external hard drive, or any other file transfer method.
Once you have transferred the file, open the terminal on the target machine (without internet access) and execute the following command:
# sudo snap ack <package-name>.assert
In the case of our sample VLC application, execute the following command:
# sudo snap ack vlc.assert
This step ensures that the system recognizes the VLC Snap package and its metadata.
Next, install the Snap packages using the following command.
# sudo snap install <package-name>.snap
For VLC, run the following command:
# sudo snap install vlc.snap
This command installs the Snap package on your system.
Modify Snap Configurations
Modifying Snap configurations allows users to tailor the behavior of installed Snap applications to suit their specific needs.
Snap packages provide a straightforward way to view and change these configurations using the terminal.
View Current Snap Configuration
To view the current Snap configuration, run the following command:
# snap get <package-name>
Replace <package-name> with the desired Snap package.
For example, to view the current configuration of Nextcloud, run:
# snap get nextcloud
This command displays the specified Snap package’s current configuration options and values.
Set Configuration Options
If you want to modify a configuration setting, execute the following command:
# sudo snap set <package-name> <key>=<value>
Replace <package-name> with the Snap, <key> with the configuration option, and <value> with the desired value.
For instance, to set the ports.http option for the Nextcloud to 8080, run:
# sudo snap set nextcloud ports.http=8080
This command sets a specific configuration option for the Snap package.
To verify the new configuration, execute the following command:
# snap get <package-name>
This ensures the new configuration option is applied accurately.
Remove a Snap Configuration
Now if you want to remove a configuration setting, run the following command:
# sudo snap unset <package-name> <key>
Replace <package-name> and <key> with the desired Snap and value.
This command removes the specified configuration option for the Snap package.
To verify if you have successfully removed the configuration, run the following command:
# snap get <package-name>
Snap Confinement and Use Cases
Snap confinement levels define the level of isolation and access control for Snap packages on your system. Understanding these levels helps you choose the appropriate one based on your use case.
The three confinement levels are:
- Strict
- Classic
- Devmode
Let us discuss each with its use cases.
Confinement #1: Strict Confinement
Snaps running in strict confinement are fully isolated from the rest of the system. They can only access their own data, and any interaction with system resources requires explicit permission.
For instance, running a password manager in strict confinement ensures that it cannot access other parts of the system without permission, providing an additional layer of security.
Use Cases
Let us see some of the use cases of strict confinement.
Use Case #1: Secure Applications
Strict confinement is ideal for running applications that handle sensitive data or require high security, such as password managers, banking apps, and VPN clients.
Use Case #2: Sandboxed Environments
Suitable for applications that should not interfere with or be affected by other software on the system, like web browsers and media players.
Use Case #3: Cross-Platform Apps
Perfect for applications intended to run consistently across various Linux distributions without modifications, such as productivity tools and communication apps.
Confinement #2: Classic Confinement
Snaps in classic confinement have the same level of access to system resources as traditional packages installed via package managers like APT or Yum. This mode bypasses strict isolation but requires manual approval.
Use Cases
Let us discuss some of the use cases of classic confinement.
Use Case #1: Development Tools
Essential for developers who need their tools to interact with various parts of the system, such as compilers, debuggers, and IDEs.
Use Case#2: System Management Tools
Useful for system administrators who need utilities that manage or interact with system-wide resources, like backup tools and network monitors.
Use Case #3: Legacy Applications
Beneficial for older applications that were not designed with confinement in mind and require extensive system access.
Confinement #3: Devmode Confinement
Devmode confinement is intended for development and testing. Snaps in this mode run with full access to system resources but provide debug output and cannot be published to the stable channel.
Use Cases
Some of the use cases of the devmode confinement are:
Use Case #1: Application Development
Essential for developers working on new Snap applications who need to test and debug their software with full system access.
Use Case #2: Debugging
Useful for diagnosing and fixing issues in existing Snap packages, allowing unrestricted access and detailed logs.
Use Case #3: Prototype Testing
Suitable for testing early software versions that may not yet be stable or secure enough for strict confinement.
View Snap Change History
Viewing Snap change history is essential for several reasons, particularly for maintaining system stability, troubleshooting, and ensuring smooth operations.
To view the Snap change history, execute the following command:
# snap changes
This command lists the changes made to Snap packages, including installs, refreshes, and removals, along with their statuses and timestamps.
If you want to know the details of a specific change, run the following command:
# snap change <change-id>
Replace <change-id> with the unique identifier displayed in the output of snap changes.
For instance, to view information about the Snap with change ID 5, run the following:
# snap change 5
This provides detailed information about the change, such as the package involved, the action performed, and the timestamp.
Switch Channels
Snap packages are available in different release channels — stable, candidate, beta, and edge — to cater to various user preferences and risk tolerances. Users can switch between these channels to meet their specific needs.
Users switch channels for various reasons including stability and new features, testing and development, and risk management.
To switch a Snap package to a different release channel, run the following command:
# sudo snap refresh <package-name> — channel=<channel>
Replace <package-name> with the desired Snap and <channel> with the target channel
Next, if you want to check the current channel of a Snap package, execute the following command:
# snap info <package-name>
Conclusion
Snap packages provide a versatile and powerful solution for application management on Linux systems. They enable developers to create easily distributable and consistent applications across various distributions.
Understanding the differences between Snap packages and traditional package management systems highlights the advantages of Snaps, such as their isolation, ease of updates, and dependency management.
Using the command line tool, users can efficiently manage Snap packages with commands like snap install, snap remove, and snap list, requiring only root privileges for installation and removal.
The Snap interface further simplifies interactions, allowing beginners and advanced users to manage applications effectively.
FAQs
Q. What is the difference between an APT package and a Snap package?
APT packages are traditional Debian packages that rely on the system’s package manager and its dependencies. Snap packages, conversely, are self-contained, including all dependencies, and run in an isolated environment, making them more portable and easier to manage across different Linux distributions.
Q. How do you install a single Snap using the command line?
To install a single Snap, use the snap install <package-name> command in the terminal. For example, snap install vlc will install the VLC media player.
Q. What are the steps involved in building Snaps?
Building Snaps involves creating a snapcraft.yaml file that defines the Snap’s metadata and build instructions. Then, use the snapcraft command to build the Snap package. Finally, test the Snap locally with snap install <snap-name>.snap — dangerous.
Q. What tools are available for Snap Development?
Snapcraft is the primary tool for Snap development, providing the necessary commands to build, package, and publish Snaps. Additionally, developers can use Multipass for testing Snaps in a clean virtual environment.
Q. How do you manage Snaps using the Snaps command?
You can manage Snaps using commands like snap install, snap remove, snap list, and snap refresh. These commands allow you to install, uninstall, list, and update Snap packages.
Q. What is the Snap file format, and how is it used?
The Snap file format is a compressed, self-contained package that includes an application’s code, libraries, dependencies, and metadata. Snap files typically have a .snap extension and are installed using the snap install <file>.snap command.
Q. What are actual Snaps and how do they function?
Actual Snaps are the real applications packaged as Snap packages. They function by running in isolated environments on top of the root filesystem, ensuring consistency and reliability across different systems.
Q. Can you create custom Snaps for individual snap service needs?
Yes, developers can create custom Snaps tailored to specific needs by defining the necessary configurations and dependencies in the snapcraft.yaml file and building the Snap using Snapcraft.
Q. How can you re-enable a disabled Snap?
To re-enable a disabled Snap, use the snap enable <package-name> command. For example, snap enable vlc will re-enable the VLC Snap.
Q. How do you perform a configuration update for a runtime snap package?
To update the configuration of a runtime Snap package, use the snap set <package-name> <key>=<value> command. For example, snap set nextcloud ports.http=8080 changes the HTTP port for the Nextcloud Snap.