Linux+: Applications 17 – Overview of apt-get


Jarret W. Buse

Linux+: Applications 17 – Overview of apt-get

To manage packages on a Debian based Linux system, we have covered the use of the dpkg command. The command dpkg only installs a single package and does not include any dependency packages. To better manage dependency packages as well as you main packages, most users often use the command “apt-get”.

NOTE: To use apt-get, you need to have superuser privileges since changes will most likely be made to the system.

Also, be aware that apt-get is similar to the command yum on a Red Hat Operating System (OS).

The apt-get command can be used for the following:

  1. Install, upgrade and remove packages
  2. Query packages
  3. Manage repositories
  4. Diagnose package issues
  5. Additional options

When using the apt-get command, repositories will sign the packages with SecureApt. Some third part repositories may not sign the packages so be aware that these packages can be intercepted by others on the Internet. When intercepted, fake packages can be sent to you since the package is not signed, it cannot be verified as authentic. The attack is sometimes called “Man in the Middle”. If any package is not signed, a message should appear to you that there is no signature and allow you to install it anyway or not. Be aware that third parties may provide software that opens a backdoor to your system to allow entrance by unauthorized people on the Internet to your system.

Repositories are locations which contain “deb” packages. Additional repositories can be added to existing list to expand the available list of packages. The repository list is kept in the path and file “/etc/apt/sources.list”.

The article for “Install, upgrade and remove packages” will contain the following subcommands:

  • install
  • upgrade
  • remove
  • dist-upgade
  • dselect-upgrade
  • purge
  • source
  • build-dep
  • download
  • autoremove

The article for “Query packages” will include the following commands:
  • apt-cache
  • apt-file
The commands and subcommands for managing the repositories article will include:

  • add-apt-repositories
  • update
  • clean
  • autoclean

The article for diagnosing package issues will include the commands:

  • check

NOTE: You may have noticed that not all of the commands listed are subcommands for the apt-get command. Some functionality exists by using the dpkg command as well as apt-cache, apt-file and add-apt-repositories. Between all of these commands, which will be covered, you will be able to manipulate packages and all necessary files.

The article covering the optional subcommands includes the following:

  • --no-install-recommends
  • --install-suggests
  • -d (--download-only)
  • -f (--fix-broken)
  • -m (--ignore-missing, --fix-missing)
  • --no-download
  • -q (--quiet)
  • -s (--simulate, --just-print, --dry-run, --recon, --no-act)
  • -y (--yes, --assume-yes)
  • --assume-no
  • -u (--show-upgraded)
  • -V (--verbose-versions)
  • -a (--host-architecture)
  • -P (--build-profiles)
  • -b (--compile, --build)
  • --ignore-hold
  • --with-new-pkgs
  • --no-upgrade
  • --only-upgrade
  • --force-yes
  • --print-uris
  • --purge
  • --reinstall
  • --list-cleanup
  • -t (--target-release, --default-release)
  • --trivial-only
  • --no-remove
  • --auto-remove
  • --only-source
  • --diff-only, --dsc-only, tar-only
  • --arch-only
  • --allow-unauthenticated
  • --show-progress
  • -h (--help)
  • -v (--version)
  • -c (--config-file)
  • -o (--option)

The basic syntax for using apt-get is:

apt-get subcommand options

NOTE: There should exist one subcommand and zero or more options. A subcommand should always be present unless the option “-h” or “--help” is used. One other command, “-v” or “--version”, also can be used alone.

When an application is using the apt-get command, the file “/var/lib/dpkg/lock” is used by the application. If another application is run which wants to use the apt-get command, it must lock the file. If the file is already locked by another application, the second application will not complete to prevent issues. When multiple applications attempt to access the same databases, corruption can occur.

If you get an error that the file “/var/lib/apt/lists/lock” is locked, this means another apt-get application is already running. To determine the problem application, try the following command:

sudo lsof /var/lib/apt/lists/lock

The output should be something similar to the following:

sudo lsof /var/lib/apt/lists/lock


synaptic 3256 root 45u REG 0,17 0 45747 /var/lib/apt/lists/lock

The output shows that the application “synaptic” has the file locked. The program is using a PID of 3256. You can close the application manually or use either command:

kill processnumber
kill -9 processnumber

NOTE: Use the PID number in place of “processnumber” to close the application.

Another possible way to unlock the file is to use he command:

sudo rm /var/lib/apt/lists/lock

At this point, perform the command “sudo apt-get update” to update the package lists and recreate the lock file. The lock file will be recreated the next time apt-get is used, but it may be best to make sure the file exists.

The overview should give you a good basis to start with the apt-get command.


  • slide.jpg
    32.9 KB · Views: 34,230

MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit:

Staff online

Members online