|

apt remove: Uninstall apt Packages in Ubuntu

How do you uninstall apt packages in Ubuntu using the terminal? It’s quite simple, actually.

If you know the package name, just use it with the apt remove command like this:

sudo apt remove package_name

Even if you do not know the exact package name, tab completion is there to help you. You may also use the older apt-get remove command here.

sudo apt-get remove package_name

Both apt and apt-get commands are pretty much alike. The new and recommended command is apt, which I would also suggest using.

If you want to remove multiple packages, you can do that in a single command:

sudo apt remove package_1 package_2 package_3

Let’s see all this in more detail.

Uninstall apt packages

The apt command gives you all the essential tools to manage the APT packages. For uninstalling a package, it provides the remove option.

sudo apt remove package_name

You need to use the exact package name. How do you get that? You can use the tab completion feature. Try entering the first few starting letters and press tab. It will show the possible package names you can use.

For example, I typed sudo apt remove mp and press the tab. My system shows that there are two installed packages with names starting with mp.

apt remove tab completion
Tab completion with apt remove command

Alternatively, you can list all the installed packages with apt and look for the package name:

apt list --installed

This will be a huge output and you may have to use the grep command to filter on the result.

I decide to remove the MPlayer from my system. The package name is mplayer (with all small letters). This is important because Linux is case-sensitive.

sudo apt remove mplayer

Installing and removing packages in Ubuntu requires that you have admin privileges. This is why you need to use sudo before the apt remove command.

It asks to enter a password. It’s your user account’s password. When you type the command, nothing is displayed on the screen. That’s expected behavior. Type the password and press enter.

As you can see in the screenshot below, it will show what packages are going to be removed. It also informs what dependency packages should be removed afterward.

apt uninstall package ubuntu
apt uninstall package ubuntu

You have to press y or the enter key to continue with package removal.

Cleaning up after package removal (optional)

As you can see in the previous screenshot, it says, “The following packages were automatically installed and are no longer required” and then lists three packages.

These are dependency packages that were installed automatically when mplayer was installed.

So, what can you do? You can use the suggested command to remove these packages.

sudo apt autoremove

Do you really need to do that? No. You can just go ahead with your work after apt remove.

The dependency packages will stay in the system. Usually, you should try running the apt autoremove commands every few weeks. It will remove all the dependency packages that are not required anymore, delete the older Linux kernel versions and thus free up disk space for you.

Dealing with configuration files after package removal

You should know that uninstalling apt package with apt remove does not remove user settings and configuration files (located under /etc directory).

This way, if you install the same application again, you may reuse your custom configuration.

Let’s take our example. Here are all the mplayer related directories before uninstalling it:

mplayer before removal
MPlayer related files before removal

After removal, you can still see some files:

files after mplayer removal
Files after mplayer removal

in certain cases, you might want the application to start afresh. You can use the apt purge command to uninstall apt applications and remove their configuration files located under /etc.

sudo apt purge package_name

Remember that even apt purge will not remove application-related files located under the user’s home directory. Those are really small files and do not take up a lot of space. If you are particular about these things, you can look for such files and manually remove them. There is no magic command for this.

Summary

To summarize:

  • The apt remove command removes the specified packages.
  • The remaining dependencies need to be removed separately with apt autoremove command.
  • It doesn’t remove configuration and other user settings. If you install the same application again, it will likely have your user-defined settings.

I hope you find this beginner’s article about removing apt package helpful.

Please let me know if certain things are unclear in the comments and I’ll be happy to answer your questions.

Similar Posts

  • Hi, one of the commands I use the most, works for Debian.
    /var/cache/apt/archives to clear the folder path:
    sudo apt-get clean

    I learned something new
    apt list –installed
    Thanks