28.2 apt install, remove, purge, and autoremove
Right, let’s talk about making your system do your bidding. Or, more accurately, let’s talk about convincing a vast, complex repository of pre-built software to gracefully land on your machine without setting anything on fire. That’s apt. It’s the concierge of your Debian or Ubuntu system, and when you learn its language, you can get it to fetch you just about anything.
The magic incantation you’ll use 90% of the time is apt install. It’s straightforward: you ask for a thing, and apt figures out how to get it, along with every other little library and dependency that thing needs to function. It’s like ordering a pizza and having them automatically send a friend with a six-pack of soda, plates, and a movie recommendation.
sudo apt install neovim
See that sudo? Yeah, you’re telling the system to install software for everyone, which is a privileged operation. Get used to typing it. Now, watch what happens. apt will present you with a plan: “Here’s the package I’m about to install (neovim), and oh, by the way, here are the 47 other packages it needs to work properly. Is this cool?” You press ‘Y’, and off it goes. This dependency resolution is the entire reason we use package managers. Without it, you’d be lost in “Dependency Hell,” manually tracking down .deb files until you weep. I’ve been there. It’s not pretty.
The Art of the Uninstall
Getting rid of software is just as important. You have two main choices here: remove and purge. Most of the time, you’ll use remove.
sudo apt remove neovim
This command uninstalls the neovim package itself but leaves its configuration files behind on your system. This is actually a thoughtful default. If you’re just troubleshooting and think you might reinstall it later, your carefully crafted configs for it are right where you left them. It’s like unplugging a appliance but not throwing away the user manual.
But sometimes, you want a scorched-earth policy. You want every trace of a package gone—its binaries, its configs, everything. That’s what purge is for.
sudo apt purge neovim
Use this when you’re sure. You’re breaking up with a package and you want it to forget your number. It’s perfect for cleaning up after a package that went horribly wrong or that you know you’ll never touch again.
The Janitor: autoremove
Here’s where apt earns its keep as your brilliant, slightly obsessive-compulsive friend. When you install a package, its dependencies are tagged as automatically installed. They’re just there to serve a higher purpose. When you later remove the main package, those dependencies become orphans. Useless. Cluttering up your system.
apt keeps a list of these orphans. Running autoremove is like telling your system, “Hey, take out the trash.”
sudo apt autoremove
It will present a list of packages that are no longer needed by anything else and offer to remove them. You should always say yes to this. It’s free disk space and a cleaner system. The one thing to watch out for is if you’ve manually installed a library that also happened to be a dependency. If the main package that pulled it in is gone, apt might try to remove it. It’s rare, but apt will always tell you exactly what it plans to do, so just glance at the list before hammering ‘Y’.
Best Practices and Pitfalls
First, always do an apt update before a big install session. The local package index on your machine can get stale. update fetches the latest list of available packages and their versions from the remote repositories. It doesn’t upgrade anything; it just makes sure apt knows what’s currently on the menu.
sudo apt update
sudo apt install the-package-i-really-want
Trying to install something that doesn’t exist? You’ll get a helpful error. But sometimes, the package name isn’t what you think. Use apt search to find the exact name.
apt search "video player"
And my final pro-tip: combine these commands for efficiency. There’s no need to wait for update to finish before typing the next command. apt is smart enough to handle the queue.
sudo apt update && sudo apt install git
The && means “if the first command succeeds, then run the second.” It’s a good habit. Now go forth and install. Responsibly.