Simplify Command-Line Package Management with APT instead of apt-get

By Michael Tunnell on November 27th, 2015

apt-instead-apt-get-main

APT, the Advanced Package Tool from the Debian project, is for managing packages by using a lot of separate tools to accomplish various tasks. In the past, users needed to know multiple command structures like apt-get, apt-cache, apt-config, and many more to utilize the full feature-set of APT.

APT was created originally to solve a lot of package management problems like putting an end to the dependency hell that so many people experienced in the early days of Linux-based operating systems. Unfortunately, APT suffers from a different kind of hell, something I call “Dispersed Documentation Hell” (DDH). The documentation related to APT is scattered in various different tools and in some cases, such as the main apt command, practically impossible to find.

For over a decade, practically all tutorials and guides for installing and removing packages on a Debian/Ubuntu based system have been suggesting apt-get to users. In the past, that was the correct suggestion because “apt” as a command hadn’t existed at the time but due to the Dispersed Documentation Hell a lot of people aren’t aware that now it does exists.

If you wanted to install a package almost all guides will suggest:

sudo apt-get install package

but now instead you can simplify that with

sudo apt install package

Some may argue that “apt” isn’t much different than “apt-get” and that is true but I think the hyphen in the command is what creates a bottleneck for many users due to its awkwardness. Using apt instead will save time and save the amount of keystrokes required to accomplish the same task.

Dispersed Documentation Hell (DDH)

apt-instead-apt-get-documentation-hell

The fundamental problem with the documentation regarding APT is that depending on where you look and how you look, you may or may not find anything at all. If you were to search Google, or DuckDuckGo, for “apt documentation” you’d find one of three types of results:

  1. apt-get related documentation
  2. Basic overview information regarding APT
  3. Completely unrelated information

If you were to throw “linux”, “ubuntu”, or even “debian” into the search query the types of results you’ll receive won’t change. The DDH is so severe that you’ll find documentation from Debian.org marked as Obsolete Documentation before you’ll find anything useful related to the “apt” command, if you ever find it at all.

Man Pages

Man Pages are documentation pages that can be used locally on your system or via online directories. Local entries may or may not be up to date depending on the version of your distro. For example, Ubuntu 15.10 has the latest man page but 14.04 does not by default. However, if you keep your 14.04 version of Ubuntu up to date with service packs then you should have the updated man page. You can check to see if you have the latest version of the man page with the command below.

man apt

On the other hand, if you were to search for the man page online then you will almost always find the old overview man page. If you were to keep digging, though, you may uncover the Ubuntu 15.10 man page which is up to date or instead you may uncover the online 14.04 man page which is out of date.

Simplify the Command-Line with APT

The list below contains the most useful options available via the apt command and what old commands they simplify.

  • apt install package(s)
    • replaces apt-get install package
    • replaces cd /Downloads && sudo dpkg -i application.deb && sudo apt-get -f install
  • apt remove package(s)
    • replaces apt-get remove package
  • apt search query
    • replaces apt-cache search query
  • apt show package(s)
    • replaces apt-cache show package(s)
  • apt update
    • replaces apt-get update
  • apt upgrade
    • replaces apt-get upgrade
  • apt list –installed
    • replaces dpkg –get-selections | grep -v deinstall
    • replaces dpkg -l
  • apt list –upgradable (sudo not required)
    • replaces apt-get -u upgrade –assume-no” (sudo required)
  • apt edit-sources
    • replaces echo ‘new line of text’ | sudo tee -a /etc/apt/sources.list
    • replaces sudo nano /etc/apt/sources.list

Edit 2016-04-01: as of Ubuntu 16.04 the following options have been added to the Debian/Ubuntu implementation of the apt command.

  • apt autoremove
    • replaces apt-get autoremove
  • apt purge package(s)
    • replaces apt-get purge package(s)

 

Linux Mint is Enhancing Simplicity

apt-instead-apt-get-linux-mint

Most of the recent operating systems based on Debian or Ubuntu have the up to date version of APT that allows for some tasks to be simplified but the Linux Mint team decided that APT should be simplified quite a few years ago. Linux Mint created a python script (started in 2009) to make APT as useful and as simple as possible. I hope that Debian sees the benefit of expanding the functionality of apt so that in the future everyone can benefit from the simplified approach that Mint is taking. The apt command can be so much better than it is right now and hopefully Debian sees this as well and brings apt to its full potential.

Linux Mint decided to make an interesting choice in their script by removing the need to use sudo. For example, if you run “apt install package” it will automatically apply sudo to the front of it during processing so the user doesn’t need to remember if something needs sudo or not, the script will apply it or not accordingly.

The list below contains the most useful additional options available via the Linux Mint apt command and what old commands they simplify. Note: the following list only applies to Linux Mint users at the moment.

  • apt autoclean
    • replaces apt-get autoclean
  • apt autoremove

    • replaces apt-get autoremove
  • apt purge package(s)
    • replaces apt-get remove –purge package(s)
  • apt depends package(s)
    • replaces apt-cache depends package(s)
  • apt rdepends package(s)
    • replaces apt-rdepends package(s)
  • apt policy package(s)
    • replaces apt-cache policy package(s)
  • apt held
    • replaces dpkg –get-selections | grep hold
  • apt hold package
    • replaces echo package hold | sudo dpkg –set-selections
  • apt unhold package
    • replaces echo package install | sudo dpkg –set-selections
  • apt download package (downloads the deb file of a package)
    • replaces LC_ALL=C apt-cache depends package |grep -v “Conflicts:\|Replaces:”|awk ‘{print $NF}’|sed -e ‘s/[<>]//g’|xargs aptitude download -r

APT: Do More with Much Less

The apt command has simplified a lot of tasks with command-line package management on the Linux (Debian-based) desktop and with Linux Mint taking the initiative to improve it further, hopefully it will help the community transition to the new method. The only command that I noticed Linux Mint’s apt script missing thus far is “apt add-repository” to replace the awkward add-apt-repository command, so I wrote a patch to add this feature to the script. I’m pleased to inform you that they have accepted my patch so this feature will be available in a future release of Linux Mint.

Michael Tunnell is a Linux expert and a long-time How-To Geek forum member.

  • Published 11/27/15
More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!