How to use apt-get command on Ubuntu Linux with examples

The apt-get command is used by system administrators on Debian based systems to work with APT software packages.

This post shows new users and students what the apt-get command is and how to use it.

Ubuntu Linux OS is probably the best system to for new users and students learning how to use and manage Linux. Ubuntu is an open-source Linux operating systems that runs on desktops, laptops, server and other devices.

When you’re ready to learn how to use the apt-get commands, follow the guide below:

About apt-get command:

The apt-get command is used by system administrators on Debian based systems to work with APT software packages. APT (the Advanced Packaging Tool) is Debian Linux software for managing .deb packages on Linux systems.

It is an efficient way to manage packages on Linux systems using the APT package management tool.

Dependencies for each package are managed automatically, upgrades and downgrades are handled carefully to ensure system stability.

Like using your mouse and keyboard to install or remove packages Linux systems. the apt-get is the way to do it on the command line for Debian based systems.

Syntax:

The syntax is the rule and format of how the apt-get command can be used. the systax’s options can be reordered. but straight format must be followed.,.

Below is an example syntax of how to use the apt-get comamnd.

apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 .]
apt-get [options] source pkg1 [pkg2 .]

Options:

The command line options are switches or flags that determined how the commands are executed or controlled. they modify the behavior of the command. they are separated by spaces and followed after the commands options.

Below are some options of the apt-get command:

updateUse the update option to retrieve new lists of packages for your system. .this option is usually used when a new source or repository has been added to the system.
upgradeUse the upgrade option to rerform an upgrade to the system. all packages that have upgrade pending will be upgraded.
installUse the install options to install new packages on the system. (pkg is libc6 not libc6.deb) . it can not be used to install packages that end in .deb
removeUse the remove option to remove packages from your system.
purgeUse the purge option to remove packages and config files.
autoremove  Use the autoremove option to remove automatically all unused packages.
dist-upgradeUse the dist-upgrade option to perform distribution upgrades. similar to the upgrade option above..
cleanUse the clean option to erase downloaded archive files. these files can build up over time and take up space.
autocleanUse the autoclean option to erase old downloaded archive files. similar to the clean option above
check Use the check option to verify that there are no broken dependencies

Examples:

Below are some examples of how to run and use the apt-get on Ubuntu Linux.

If you want to install a package called libc6, you run the commands below. The command will fetch all sources on the computer for a package called libc6 and install, along with all its dependencies and configuration files.

sudo apt-get install libc6

If you want to remove libc6 package from your system, you run the commands below.. the commands remove the libc6 and all its dependencies..

sudo apt-get remove libc6

After removing libc6 package from your system, you can use the clean option to clean the local disk of downloaded archived files for installed packages.which can help to clean up your disk.

sudo apt-get clean

To download the archive for the package libc6 in the current working directory, run the commands below.

sudo apt-get download libc6

The command options above also have sub options that can be used to manage packages. [sudo apt install -f libc6]

Use the -f–fix-broken sub option to fix or attempt to correct broken dependencies.
Use the -m–ignore-missing–fix-missing sub option to ignore missing packages.
Use the -y–yes–assume-yes sub option to automatically select yes to prompts.
Use the –force-yes sub option to force yes when installing / upgrading or removing packages.
Use the –reinstall sub option to reinstall packages that are already installed..
Use the –no-download sub option to for apt tool to only install from download archive files on the local system.

When you run apt-get with the –help option, you’ll see the help text below:

Usage: apt [options] command

apt is a commandline package manager and provides commands for
searching and managing as well as querying information about packages.
It provides the same functionality as the specialized APT tools,
like apt-get and apt-cache, but enables options more suitable for
interactive use by default.

Most used commands:
  list - list packages based on package names
  search - search in package descriptions
  show - show package details
  install - install packages
  remove - remove packages
  autoremove - Remove automatically all unused packages
  update - update list of available packages
  upgrade - upgrade the system by installing/upgrading packages
  full-upgrade - upgrade the system by removing/installing/upgrading packages
  edit-sources - edit the source information file

That’s it!

Hope you like it and please come back soon for more Ubuntu Linux command!

You may also like the commands below: