Skip to main content

Module 8: Package Management

Lesson 73: apt-get Command

In this lesson, you'll learn how to use the apt-get command to install, upgrade, remove, and manage software packages in Debian-based Linux distributions.

The apt-get command is a powerful and free command-line program used to work with Ubuntu's APT (Advanced Packaging Tool) library.

It facilitates various package management tasks, including the installation of new software packages, removal of existing packages, upgrading of existing software packages, and can even be used to upgrade the entire operating system.

It served as the primary package management command in Debian-based Linux distributions before the introduction of the apt command.

apt-get Command Syntax

The syntax for the apt-get command is as follows:

$ sudo apt-get [OPTIONS] [COMMAND]

Here, OPTIONS represents any additional flags or modifiers you can use with the command, and COMMAND specifies the action you want to perform, such as installing, upgrading, removing, or searching for packages.

apt-get Command Options

Command/Option Description
update Resynchronize the package index files from the sources
upgrade Upgrade all currently installed packages
install Install or upgrade a package
remove Remove a package but keep its configuration files
purge Remove a package and its configuration files
autoremove Remove packages that are no longer required
clean Remove downloaded package files from the cache
autoclean Remove old downloaded package files from the cache
check Update the package cache and check for broken dependencies
download Download a package without installing it
source Download the source code of a package
build-dep Install the build dependencies of a package
changelog Download and display the changelog of a package
--no-upgrade Prevent upgrading an already installed package
--only-upgrade Only upgrade the package without installing new packages
--download-only Download only, without installing or unpacking
--compile Download, unpack, and compile the source code

Let's look at some of the useful examples of the apt-get command.

1. Update System Packages

The apt-get update command is used to resynchronize the package index files from the sources specified in the /etc/apt/sources.list file.

This command fetches the packages from their respective locations and updates them to newer versions:

$ sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Fetched 229 kB in 2s (114 kB/s)
Reading package lists... Done
Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’