Software & AppsOperating SystemLinux

How To Stop apt from Installing Snap Packages

Ubuntu 21

In the world of Linux, package management is a crucial aspect of system administration. One of the most popular package management systems is APT (Advanced Package Tool), which is used in Debian-based distributions like Ubuntu and Linux Mint. However, there may be situations where you want to prevent APT from installing certain packages, such as Snap packages. This article will guide you through the steps on how to stop APT from installing Snap packages.

Quick Answer

To stop APT from installing Snap packages, you can remove the ‘snapd’ package from your system using the command ‘sudo apt-get autopurge snapd’. Additionally, you can create a configuration file to prevent the installation of ‘snapd’ by running the command ‘cat <<EOF | sudo tee /etc/apt/preferences.d/nosnap.pref’. However, please note that preventing the installation of Snap packages may result in installation failures for packages that rely on Snap.

What are Snap Packages?

Snap is a software packaging and deployment system developed by Canonical for the operating systems that use the Linux kernel. The packages, called ‘snaps’ and the tool for using them ‘snapd’, work across a range of Linux distributions and allow upstream software developers to distribute their applications directly to users. Snaps are self-contained applications running in a sandbox with mediated access to the host system.

Why Prevent APT from Installing Snap Packages?

While Snap packages can be advantageous due to their simplicity and cross-distribution compatibility, they may not always be the best choice for every user. Some users prefer to use native APT packages for various reasons, such as:

  • Performance: Snap packages can be slower to start up than native APT packages.
  • Disk Space: Snap packages can take up more disk space as they contain all their dependencies.
  • Updates: Snap packages are updated automatically, which some users may not prefer.

How to Stop APT from Installing Snap Packages

Here’s a step-by-step guide on how to prevent APT from installing Snap packages.

Step 1: Remove snapd from Your System

The first step is to remove ‘snapd’, which is the package that handles snaps on your system. This can be done with the following command:

sudo apt-get autopurge snapd

Here, ‘sudo’ is used to run the command with root privileges, ‘apt-get’ is the APT package handling utility, ‘autopurge’ is a command that removes a package along with its configuration files, and ‘snapd’ is the package to be removed.

Step 2: Create a Configuration File to Prevent snapd Installation

Next, create a special configuration file for APT to prevent the installation of ‘snapd’. Run the following command:

cat <<EOF | sudo tee /etc/apt/preferences.d/nosnap.pref
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOF

This command creates a file named ‘nosnap.pref’ in the ‘/etc/apt/preferences.d/’ directory. The ‘cat’ command is used to create the file, ‘sudo’ is used to run the command with root privileges, and ‘tee’ is used to write the output to the file.

The contents of the file instruct APT to prevent the installation of ‘snapd’. The ‘Package: snapd’ line specifies the package to be blocked, ‘Pin: release a=*’ applies the configuration to all versions of the package, and ‘Pin-Priority: -10’ sets the package priority to -10, which prevents the package from being installed.

Important Note

Please note that preventing the installation of Snap packages may result in installation failures for packages that rely on Snap. If you encounter such failures, you will need to manually install the package from an alternative source, such as from source code or a different package manager.

Conclusion

By following these steps, you can prevent APT from installing Snap packages on your system. This can be useful if you prefer to use native APT packages for performance, disk space, or update reasons. However, remember that this might lead to installation failures for packages that depend on Snap, and you’ll need to find alternative installation methods for those packages.

What is APT?

APT stands for Advanced Package Tool. It is a package management system used in Debian-based distributions like Ubuntu and Linux Mint. APT allows users to install, upgrade, and remove software packages on their systems.

What are Snap packages?

Snap packages are a software packaging and deployment system developed by Canonical for Linux distributions. They are self-contained applications that run in a sandbox with mediated access to the host system. Snaps are designed to work across different Linux distributions and allow software developers to distribute their applications directly to users.

Why would I want to prevent APT from installing Snap packages?

There are a few reasons why someone might want to prevent APT from installing Snap packages. Some users prefer to use native APT packages for performance reasons, as Snap packages can be slower to start up. Others may want to save disk space, as Snap packages contain all their dependencies, which can take up more space. Additionally, some users may prefer to manually update their packages instead of having Snap packages automatically updated.

How can I remove snapd from my system?

To remove snapd from your system, you can use the following command: sudo apt-get autopurge snapd. This command will remove the snapd package along with its configuration files.

How do I create a configuration file to prevent snapd installation?

To create a configuration file to prevent snapd installation, you can run the following command: cat <<EOF | sudo tee /etc/apt/preferences.d/nosnap.pref. This command will create a file named ‘nosnap.pref’ in the ‘/etc/apt/preferences.d/’ directory. The contents of the file will instruct APT to prevent the installation of ‘snapd’.

What should I do if I encounter installation failures for packages that rely on Snap?

If you encounter installation failures for packages that rely on Snap, you will need to find alternative installation methods for those packages. This could involve installing the package from source code or using a different package manager.

Leave a Comment

Your email address will not be published. Required fields are marked *