How To COMPLETELY Remove Applications On Linux

Sci-Republic
4 followers
Oct 20, 2022
Some of the most frequently asked support questions regarding Linux involve package
management. How can I update my software, install software, remove software? And regarding removing
software, one of the most frequently asked questions is how can I completely remove a
program from my system? And by completely remove, I'm not talking about just removing the executable
binary, the actual program itself. I want to remove all its dependencies, the libraries,
any kind of specific config files that were generated when I installed that program. I want
everything associated with that program removed from my system. How can I do that? Well, let's
discuss it. Now, there are so many different package managers available on Linux. There's so
many ways to install software on Linux. I can't possibly talk about every single package management
system, so I'm just going to cover some of the most popular ones on this video. By far, the most
package manager on Linux is the apt package manager. The apt package manager is the package
manager for Debian and Ubuntu and all distributions based on Debian and Ubuntu. The apt package
manager is also used in PC Linux OS, which is an RPM distribution, oddly enough, but it uses the
apt package manager. So, let's go ahead and open a terminal here inside Ubuntu is what I'm
demonstrating this on. Typically, to remove software using the apt package manager, you would
sudo apt remove and then the name of the program, whatever it happens to be. If I was, you know,
uninstalling Firefox, for example, sudo apt remove Firefox. Now, the problem with the sudo apt remove
Firefox command here is that it's just going to remove the program Firefox. It's not going to
remove any configuration files that were placed on the system when you installed Firefox. And this
really is standard practice with most remove or uninstall commands with most Linux package
managers. It's typically when you want to install a program, it doesn't remove all the associated
config files and stuff like that. It doesn't remove dependencies most of the time. So, how do
you get rid of everything? Well, here inside Debian or Ubuntu using the apt package manager, instead
of sudo apt remove, you want to run the command sudo apt purge name of program. And when you run
this command, it should remove the program itself. It should also remove all system-wide
config files. And by system-wide config files, I mean config files that live somewhere inside the
root file system, not in your home directory. These are not user-specific config files. These are
system-wide config files. You typically think of them as the default config files that are
usually installed when you install a program. Now, one thing sudo apt purge doesn't do is it
doesn't automatically remove the dependencies that were needed. If Firefox had some dependencies
and they're no longer needed, they don't get uninstalled right away. What you would need to do
is somewhere along the way, you want to run the sudo apt auto remove command, and this will get
rid of any unneeded dependencies, any orphaned packages and things like that. And typically,
you don't necessarily have to run this command yourself. A lot of times when you just update
your system with a sudo apt update and sudo apt upgrade, a lot of times the app package manager
is smart enough to let you know when you have some unneeded stuff on your system, and it will
actually prompt you to run the apt auto remove command when you need to. Now, that takes care of
almost everything that was associated with that program. Once you run sudo apt purge, name of
program, and then you also do the sudo apt auto remove, just make sure there's no unneeded
dependencies still on the system. At that point, everything associated with that program should be
gone except any user config files. So these are config files that live inside your home directory
on Linux. Typically, let me open the graphical file manager. Typically, on Linux, you'll have
a config folder. Let me show hidden files. I believe control H shows hidden files in most
file managers. There it is. And we have a folder here called dot config. Let's go into the dot
config directory. And then you see all of these various folders. For example, Nautilus, which is
the file manager I'm in, has a config file, right? So it has a config directory where I could put some
config information. There is nothing in this directory. It's an empty directory. Let's see if
gedit has a config file that actually is here. Yeah, there is a file associated with gedit, which
is a plain text editor. So if I uninstalled gedit right now, I did a apt purge, this directory is
still going to be here. The reason is this is in my home directory. It's one of my own config files.
It's a user config file that I could edit and manage myself. And package managers on Linux
typically can never touch your home directory. They are not allowed to touch your home directory
or any files or directory in your home directory. They're just not they're not given that kind of
permission. And that's done for safety reasons. Let me go back to the terminal here. And just to
verify this is the case, if I do a sudo apt purge gedit, let's go ahead and remove it. And you can
see gedit is going to be removed. These were some of the packages that are no longer necessary. So
we'll do an apt remove to remove those packages once we uninstall gedit. So now let's do the
sudo apt auto remove. Let's get rid of those unneeded dependencies because we removed gedit.
So those are no longer necessary. And now if I go back to the file manager, you can see in our
.config directory, we still have this gedit directory with a gedit config file. It can't
remove that. Package managers, again, they're not allowed to touch your home directory. So to remove
this, what you would have to do is you would just have to delete it yourself. I hit and delete on
the keyboard on that directory. It's gone. Now, the reason these package managers can't touch your
home directory is because obviously it would be dangerous because all of your user data, of course,
lives in your home directory. Typically you save like all of your documents and home slash documents
and all of your videos, home slash videos, yada, yada, yada. Package management systems could be
dangerous if they were allowed, for example, to move files, delete files, you know, it could
cause you some data loss. That's why package managers like app and pacman and things like that,
they will never touch your home directory. So your user config files, you always are responsible
for deleting those. You have to go and manually delete those yourself. Now let's talk about how
to do what we just did using the pacman package manager, which of course is the package manager
on Arch Linux and all distributions based on Arch Linux. So let me open a terminal. I'm going to
zoom in. So typically to remove a package in pacman, most people are probably going to run
pacman dash capital R and then the name of whatever program that you want to uninstall.
This removes just the program. It does not remove those system-wide config files.
It doesn't remove dependencies, but we can take care of that. If instead of just dash capital R,
I added NS to that. Now what this will do, this will remove the program and it will also remove
all dependencies associated with that program. And that pretty much takes care of everything.
It's kind of like the sudo apt purge and the sudo apt auto remove command all in one command here.
So pacman dash capital R lowercase NS will take care of everything except any user config files.
So anything in your actual user's home directory, you know, home slash dot config slash name of
program. You'll have to go find that stuff yourself and delete it manually. Everything
else though, everything that's in the root file system associated with this program and all its
dependencies, they should be removed automatically with this command. Now let's talk about snap packages.
So if I do a snap list, I'm not sure what snaps I have installed on the system. Let me get a few here.
Typically, well, let me install a snap package that I know exists. I'm going to do a sudo snap
install corny jokes. Corny jokes is really just a weird little funny program that really serves
no purpose. It's just a nice small program that serves as a good example of how to install a
program using snap. So sudo snap install corny jokes. Now that I've done that, let's see what
all that installed on my file system. So if I do a sudo find on root, which is searching in the root
directory. So search my entire file system using the find command dash I name and sensitive name
search for the string corny jokes. This may take a minute since it's searching the entire file system
and it finished running that search using the find command. So these are all the corny jokes files
and directories on the system. We do have one in our home directory at home slash DT slash snap
because snap has a directory in the home directory and then corny jokes. So this would be a user
specific corny jokes stuff living in the home directory, right? But then everything else is in
the root file system. You can see most of it is in slash var slash var slash lib slash snap D.
Typically where all the snap stuff, the system wide snap stuff exists. So the typical command
to remove a snap pack is sudo snap remove corny jokes. So let's go ahead and remove corny jokes
with snap remove. Now that I've done that, if I run that sudo find command on root again for the
string corny jokes, let's see if it actually removed everything. And as you can see, it removed
everything in the root file system, but it cannot go in the home directory. It is not allowed to
remove anything from your home directory. And again, that's typical with package management
systems. They're just not allowed to do that. So once again, if you want to go and delete that
particular directory, what you would need to do is just go into your file manager yourself,
go in your home directory slash snap slash corny jokes, and just delete that yourself. Now let me
clear the screen. Let's talk about flat packs. Let me do a flat pack list. See what all I have
installed as a flat pack currently. Now, typically to uninstall something with a flat pack, you would
do a sudo flat pack uninstall, I believe. And then, well, I don't actually use ungoogled Chromium.
Let me actually remove that. Let me just copy that and then paste that. And you can see it wants to
remove ungoogled Chromium or ungoogled Chromium codecs. Actually, we want both of those removed.
One is a dependency of the other. So that should remove everything associated with ungoogled
Chromium, but let's actually do a sudo find on root dash iname. And let's just see, do a search
for the string ungoogled. And yes, there is no file or directory on the system anymore that has
the string ungoogled. So I do think it actually deleted everything, but there is a flag, I believe,
associated with flat pack. So if I did a flat pack uninstall and then dash dash delete dash
data, I believe that is another kind of command that will also make sure that all data associated
with the program, everything gets deleted. Obviously it won't go in your home directory
and like go into .config and remove any of your user config files. Once again, you're going to
have to do that yourself. Probably the easiest package management system to manage as far as,
you know, getting rid of everything associated with a program or app images. So let me actually
open my graphical file manager. Let me go in my home directory slash applications. So this is
your home directory slash applications with a capital A. This is where all app images should
live on your system. And with app images, there's not really a package manager necessarily. You
don't go to the command line to remove software with app images. They're these self-contained
binaries. They're these self-contained binaries, but it's really an archive. It includes the
binary, the program itself. It includes all the dependencies. So for example, if I wanted to
remove, for example, this LibreOffice app image and I just delete it and just hit the delete key,
right? LibreOffice, that app image is gone. Everything associated with LibreOffice,
all the dependencies, they were all in that app image. So there's nothing else for me to do. The
only thing that could be left on the system is if I had a specific config file for LibreOffice,
wherever LibreOffice puts config files. I don't even know if you have user config files
associated with LibreOffice. I'm sure you do. They probably be in your home directory dot
config slash LibreOffice. If that exists, I would have to go and manually delete that myself.
Another thing we should talk about briefly is what happens if you build packages yourself? You
build a program from source. How do you completely remove that stuff from your system? Well, you have
to manage that yourself because the package manager doesn't know about programs you build
from source. For example, let me go into some of my source code stuff here. So I maintain my own
builds of ST, for example, the suckless simple terminal, right? And this is the source code for
it. So if I want to actually remove ST from my system, what I would need to do is I would need
to find out where, when I actually make the package and build the package, where does the
binary get placed? Where does any extra libraries get placed? I would have to go find those on the
system. And there's no easy way to figure this out other than possibly reading the make file.
So if I read the make file here and I'll open it in NeoVim, that gives me some idea of what
happens when you actually make the package. So you can see directories it makes and things that
moves around. It copies certain files. It copies the ST binary to slash bin, for example. It also
tells me where the man page gets placed. It also tells me where the readme information gets copied
to. So it tells me where a lot of the files associated with ST gets placed on the system
just by reading that make file. And this is really one of the reasons why you typically don't want to
build software from source unless you have to. It's because some of these programs, they'll put
all kinds of stuff all over your file system. They're placing files everywhere on the file
system. None of this stuff is managed by any package manager, right? Because you built it
from source, you're managing all of that stuff yourself or you're supposed to. And what happens
if you build a lot of programs from source? Over time, you're going to have all this extra cruft
just hanging out on your file system. So unfortunately, that is something that you're
going to have to deal with yourself or what you would probably need to do. What I typically do is
I avoid building anything from source unless absolutely necessary. Unless I can't find it in
any package manager available on Linux, then I'll build it from source. And of course, I didn't cover
every single package manager available on Linux, but they're all very similar. All of them have a
way to uninstall a program with all its dependencies and all its system-wide config files. None of them
will let you delete user data. So anything in your user's home directory, they cannot touch.
So make sure you always go into .config and look for any config files associated with that program
and delete those. Also go into home slash .cache and delete any old cache files associated with
that deleted program. And then you may also want to go and look in home directory slash .local
name of program for some extra libraries that may be hanging out in that particular directory.
Now, before I go, I need to thank a few special people. I need to thank the producers of this
episode. Gabe, James, Matt, Maxim, Mehmet, Mitchell, Paul, Wes, WhyYaBaldHomie, Alex,
ArmoredDragon, Chuck, CommanderRainGreed, Iokai, George, Lee, Marstrom, Nate, Erjan,
Alexander, Paul, PeaceArch, Fedora, Polytech, Realities4Less, Red Prophet, Roland, Steven,
ToolsDevler, and Willie. These guys. They're my highest tiered patrons over on Patreon. Without
these guys, this episode would not have been possible. The show is also brought to you by
each and every one of these fine ladies and gentlemen. All these names you're seeing on
the screen right now. These are all my supporters over on Patreon because I don't have any corporate
sponsors. I'm sponsored by you guys, the community. If you like my work and want to see more videos
about Linux and free and open source software, subscribe to DistroTube over on Patreon. These
guys. When it comes to removing a program, AppImage for the win.
