How to Use APT and Say Goodbye to APT-GET in Debian and Ubuntu
Linux is in a state of permanent evolution. Often the changes are hidden, such as behind the scenes developments to the kernel and other underlying code. But occasionally, the user has to adjust to a new way of working.
While many enhancements in computing can be jarring and require a different mindset, this isn’t true of the development of the apt-get command. Rather than replace it completely, Debian-based systems (such as Ubuntu, Linux Mint, and the Raspberry Pi’s Raspbian ) are continuing its use alongside its replacement, the simpler apt command.
But why are they doing this, and what has really changed?
APT vs. APT-GET
There is a sound logic in introducing the apt command. Previously, access to the Advanced Package Tool has been via the apt-get and apt-cache set of commands (or via Synaptic or other package managers on the desktop). However, due to the way these have been expanded over time, things have become rather disorganized.
By introducing apt, which features the most commonly used options from apt-get and apt-cache, not only are the commands slightly shorter, there are also fewer of them. This avoids duplication and other problems that have arisen over the years.
But apt isn’t just about unifying two similar, disorganized command structures. It also enhances the command line experience. For instance, a progress bar is displayed when installing or removing a program.
So, that’s why apt was introduced. But why should you use it? These examples explain.
In Short: No More GET
We’ve previously looked at the apt-get command in-depth . The commands you previously used can still be employed, simply by dropping the “-get” portion.
apt-get install [packagename]
apt install [packagename]
In general, this change occurs across all previous apt-get commands. But with the introduction of apt comes some extra functionality. Software upgrades and removal now all have additional options, from installing multiple packages to purging packages from your system.
Get a Full Upgrade
You probably already know about the update and upgrade commands that work with both apt and apt-get. In short, update refreshes the package information from the repositories , while upgrade will upgrade any actually installed packages.
The new apt command introduces this new command, full-upgrade.
sudo apt full-upgrade
With this command, not only will the packages be upgraded, any old packages that must be removed as part of the upgrade will be discarded. The standard apt upgrade command doesn’t do this.
Install Multiple Packages
In a rush, and need to install more than one software package? Or simply want more efficiency from your software installation command?
The apt install command has evolved, enabling you to now install multiple packages with a single command. Simply name the packages in turn after the install command:
sudo apt install [package_1] [package_2] [package_3]
If an app is already installed, then apt will check the database for a later version and install this instead. Simple!
Install a Package Without Upgrading
It’s possible that in some circumstances you may need to install an existing package (perhaps to repair it) without upgrading. Fortunately, apt also simplifies this scenario:
sudo apt install [packagename] --no-upgrade
Meanwhile, you can download an upgrade to an uninstalled package and leave it uninstalled with:
sudo apt install [packagename] --only-upgrade
Admittedly that last command is an unusual scenario for most, but it’s worth knowing about.
Install a Specific Package Version
What if you wanted a specific version of an application? This might happen if you find that the latest update breaks a feature that you use. You’ll need to perform some research for this, in order to make sure you know the version number of the package.
Once you’ve found it, simply use this command to specify the package name and the intended version:
sudo apt install [packagename]=[version_number]
Remember that subsequent upgrades can undo this and replace the desired version with the latest. As such, you will need to repeat this command (unless the broken feature is restored by the developers).
List Upgradeable and Installed Packages
Another new aspect to installing software with apt on Debian based systems is the list option. This will output a list based on the specified condition.
For instance, you can view a list of packages that have an upgrade pending:
apt list --upgradeable
More simply, a list of installed packages:
apt list --installed
A third option for list is also available. This will display a list of all packages that are available for your operating system and computer.
apt list ----all-versions
(Notice the number of “-” characters in the command: four!)
Remove vs. Purge
The old method of removing a package with the remove command still works with apt. Use it as a reverse of the installation, specifying the package name:
sudo apt remove [packagename]
However, there is also the purge command, which works in much the same way.
sudo apt purge [packagename]
But what’s the difference?
Well, apt remove simply removes binaries, but this results in residual files being left behind — configuration files, usually.
With apt purge, however, everything related to the files is removed: binaries, config files, the lot.
Cleanup With Autoremove
Commands like remove and purge might be used to discard unwanted software on your system. In the old days of apt-get, more efficient methods of housekeeping would be available using clean and autoclean.
With apt, there’s just a single function: autoremove. Once entered, this will remove libraries and packages that are installed automatically, usually as dependencies for the desired applications. As long as these packages remain disassociated with required apps, they can be discarded.
sudo apt autoremove
And of course, this will result in important disk space being freed up !
New Commands and Better Functionality
With the apt-get command you can update, upgrade, install and remove software on Debian-based Linux operating systems. But with the simpler apt command, you can do so much more!
But which do you prefer? Will you be holding onto apt-get until it is fully deprecated, or do you fully embrace apt? Tell us how you feel — and any commands you think we should have included — in the comments box.
Image Credits: Brian A Jackson/Shutterstock
Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.