Connect with us

Website

How To Uninstall A Package In Ubuntu

Published

on

How To Uninstall A Package In Ubuntu

Ubuntu is a great choice for your VPS OS. While I personally prefer to use CentOS due to familiarity, Ubuntu wins for its fast release cycle, user-friendliness, and willingness to adapt to new technologies faster than RHEL-based systems. One example that we’ll touch upon in this tutorial is Snap packages, which come bundled with all their dependencies, don’t require any additional repositories, and also run sandboxed.

One of the first things you need to learn when starting with Ubuntu is how to install and uninstall packages. If you’re not used to the command line, it can be a bit of a learning curve, but it’s really not hard. Most of the time, if you’re installing standardized packages, it just requires a line or two, and before you know it, you’ll be installing and uninstalling packages like a pro! One thing to remember is package management hygiene, which I’ll also discuss below.

So let’s get started.

Ubuntu Package Management

A package is a like an executable “.exe” file or “.msi” file in Windows. But it’s not a binary – it’s actually just a compressed file that contains all the binaries your system needs to run the program. It also contains metadata that tells Linux where to install the files. Snap packages also contain the package’s dependencies – files required for it to run.

For Ubuntu specifically, packages come with the “.deb” extension. DEB stands for Debian – the Linux distribution, whose architecture Ubuntu uses as its base.

Advertisement

Ubuntu Package Managers – APT, DPKG, and SNAP.

Just like in Windows, the Linux system keeps track of which packages are installed, along with how to remove them. Without this, you’d quickly lose track of what you installed and clutter up the system, leading to instability and a bloated OS. To manage packages in Ubuntu, you can use either APT or DPKG.

APT is usually better, since it’s more high-level, downloads the packages, and installs the dependencies for you. DPKG is actually the package on which APT relies, so it’s more low-level. DPKG doesn’t download packages or resolve dependencies. That’s why, for this tutorial, I’m only talking about installing and uninstalling packages in Ubuntu using APT.

Snap packages are different, in that they’re sandboxed from the rest of the operating system packages, and Ubuntu also updates them automatically in the background.

Example Package in Ubuntu

One neat application to monitor Ubuntu is called “btop”. Here’s a screenshot showing the display of system resources:

Btop Screenshot on Ubuntu
Btop Screenshot on Ubuntu

Below, I’m going to use this for my examples.

What You Need to Use APT for Uninstalling a Package

To manage packages in Ubuntu, you need to have administrative rights. This means either logging in as the root user (not recommended) or gaining administrative access by being a “sudo” user. Not all users can gain administrative access.

Advertisement

The second thing you need is the exact name of the package. Since we’re using the command line, there’s no point-and-click.

Finding the Exact Name of the Package to Uninstall

Let’s say I want to confirm that the name of the package is “btop”. I use the following command:apt-cache search btop

Which gives me this output:

Search for the Exact Package Name
Search for the Exact Package Name

So I know that I have the right name.

If you don’t remember the package name at all, you can list all the packages installed, sorted alphabetically by using the following command:dpkg –get-selections

From the above list, you can scroll down till you find the package you want. Perhaps you remember what it starts like, and you can find the package name here. If you want, you can filter the above list to only show packages matching a specific keyword like this:dpkg –get-selections | grep keyword

Advertisement

So for btop, the output looks like this:

Using dpkg to Filter by Package Name
Using dpkg to Filter by Package Name

Once you’ve found the package name, it’s time to uninstall it.

How to Uninstall an Ubuntu Package Using APT

To uninstall a package like btop, I use the following command:apt remove [package name]

So for btop, the command is:apt remove btop

If you get a “permissions denied” error, then you need to prefix the commands with “sudo” like this:sudo apt remove btop

This will ask you for your password, then the command will go through. Here’s a screenshot:

Advertisement
Uninstalling a Package in Ubuntu
Uninstalling a Package in Ubuntu

As you can see, we’ve removed the “btop” package!

Purging Packages from Ubuntu Instead of Uninstalling

While using “apt remove” works well, it doesn’t completely remove everything related to the package. It leaves in place configuration files so that if you install the package after removing it, you can pick up where you left off. For many, this is a good thing, but for others, it’s a waste of space. Not everyone likes to have tons of configuration files lying around.

To remove a package along with all its configuration files, use “apt purge” instead. So this will be the command to remove the btop package:sudo apt purge btop

Remember though, that if you’re temporarily removing a package only to add it back soon after, then it might be beneficial to retain your configuration files so that you don’t lose all your customizations and saved preferences.

Removing Snap Packages on Ubuntu

As explained earlier, Snap packages are a unique innovation where a package comes with all its dependencies installed, so there’s no need to add any repositories. There are a number of useful snap packages – one of which is called “canonical-livepatch”, that allows Canonical to deliver updates to your Ubuntu system without needing to restart the server. This is beneficial for systems that require high availability and uptime.

If you already have a snap package installed on your Ubuntu machine, you can uninstall it using the following command:sudo snap remove [package name]

Advertisement

Here’s a screenshot of me removing the “btop” package after having installed it as a snap package instead of a regular one:

Removing an Ubuntu Package with Snap
Removing an Ubuntu Package with Snap

It’s easy!

Purging Package with Snap on Ubuntu

Like the apt command, removing a snap package with “snap remove” retains the configuration data of the package in the form of a “snapshot”. These aren’t the direct equivalent of configuration files, but they’re a backup of the configuration files. If you want to remove this snapshot, you first need to obtain the snapshot ID of the package whose configuration data you want gone, and then instruct Ubuntu to forget it.

To obtain the snapshot ID, use the following command:snap saved

This will list the IDs of all saved snapshots like this:

Get the Snapshot IDs of Removed Snap Packages in Ubuntu.
Get the Snapshot IDs of Removed Snap Packages in Ubuntu.

In the above example, the snapshot ID of the btop snap package is 1. To remove it, we use the “snap forget” command like this:sudo snap forget [#snapshotID]

Here it is in action:

Advertisement
Snapshot Forgotten
Snapshot Forgotten

And you’re done!

Conclusion

As you can see, uninstalling packages in Ubuntu is easy. Just remember to purge or forget them if you don’t plan to reinstall them, otherwise, they waste space and clutter up your system.

Stephen Oduntan is the founder and CEO of SirsteveHQ, one of the fastest growing independent web hosts in Nigeria. Stephen has been working online since 2010 and has over a decade experience in Internet Entrepreneurship.

Continue Reading
Advertisement
Comments

Trending

Copyright © 2024 SirsteveHQ. All Rights Reserved.