Getty Images

Tip

Ubuntu snap vs. apt: Which package manager to use and when

Choosing an appropriate package manager depends primarily on your organization's specific IT ecosystem. Determine when snap or apt is the better call.

IT teams that run workloads on Ubuntu Linux have not one but two software package managers to work with: snap and apt.

Although snap and apt both automate software package installation, management and removal, they work in different ways. An organization's choice between snap vs. apt depends on its IT priorities.

What are snap packages?

Snap is a package management system by Canonical, the company that develops the Ubuntu Linux distribution. Snapcraft is the formal name of the system that manages snap packages, but the system is commonly referred to as snap. Although snap was created for Ubuntu, it expanded in 2016 to support most mainstream Linux distributions.

Snap packages an application as an archive that contains the binary code, data and libraries required to run said application, including any external dependencies.

When you execute the application, snap unpacks the archive and the application runs in a sandboxed environment -- similar to, but not the same as, a Docker container.

For example, to install the gedit text editor, you would use the command below.

snap install gedit

When you run this command, snap downloads the snap package for gedit from whichever snap repositories are configured for your system. You can also remove installed snap packages with the snap remove gedit command.

What is apt?

Apt is a Linux package management tool used on Ubuntu and a variety of other Linux distributions. Introduced in 1998, apt has become a widely supported, popular option to install, update and remove Linux software.

Apt manages Debian packages, known as debs. Like snaps, each deb contains the application code, data and libraries required to install an application. Debs also define the application's dependencies, such as any other software the application requires to run. When you install a Debian package via apt, apt installs the application's dependencies automatically.

Apt installs data permanently into Ubuntu's file system, from which the applications run. The applications run as standard processes directly on the host system, rather than in sandboxed environments.

And, like snap, apt installs packages using simple commands.

apt install gedit

Uninstall the package with the apt remove gedit command.

Differences between snap and apt

Snap and apt seem similar on the surface: They both enable application management via packages, and enable you to install and remove software with simple commands. In fact, many snap and apt commands, such as the install and remove commands, are identical.

Where snap and apt differ is in how they package software.

Where snap and apt differ, however, is in how they package software. Snap includes everything required to run an application -- including its dependencies -- in a single package, but apt expects users to deploy dependencies as separate packages alongside the app package.

This might seem like a minor difference, but it has several important implications for how snap and apt software function:

  • Software versions. Apt installs software directly to your system, so you can install only one version of each application in use. However, while there are ways to manage conflicting application versions with apt, it's not a clear or simple process. With snap, it's easy to install multiple application versions on the same system.
  • Package creation. Snap packages are easier to create than apt packages in that you can bundle the dependencies into the package, rather than define them and expect that the user's system has the right dependencies available.
  • Package removal. Because all application data and dependencies in a snap package are self-contained, you can remove the entire application by removing the snap. Although apt also removes all data associated with an application, in most cases there is a risk that apt will fail to delete some data when you remove an application. This leaves cruft on your system.
  • Security. In some respects, snaps are more secure because they can run without root privileges, although snap expects root privileges by default to install snap packages to your system. Debs require root privileges. Theoretically, it's possible to unpack a Debian package and run the data as a non-root user, but that's not how the packages work, and it will produce a plethora of errors and issues.

In all these respects, snap makes for a cleaner, simpler software management experience. On the other hand, apt packages have their advantages too. For one, they are smaller because they don't bundle dependencies. Installing software with apt results in more efficient storage space use. Applications installed via apt are also likely to start faster because the application packages don't need to decompress before they run; instead, the packages decompress at installation time.

In addition, apt is an older, widely used package management system, which has some advantages. Snap is, at time of publication, associated primarily with Ubuntu, and although it can run on other distributions, it's not installed by default. If you want to create packages to use across multiple Linux distributions, apt is a better choice.

When to use snap vs. apt

Snap is a good choice for IT operations teams whose main package management needs revolve around software built in house. Because snap eases package builds and provides more control over package management and performance, it leads to a smoother overall experience for IT teams that must both create and deploy software, such as a combined DevOps team. Snap is also an option for use cases where an IT team can't run software as a root user for security reasons, as noted above.

Apt makes sense when most of the software you run on Ubuntu comes from third parties. Apt is also a better choice for businesses that run multiple types of Linux, given apt's support across most Linux distributions.

But you can also use both snap and apt concurrently. They can operate on the same system, but to install the same software in both snap and Debian packages will waste resources.

Next Steps

How to use Linux package managers

Dig Deeper on Systems automation and orchestration