Kiến Thức Linux

How to Use the Apt-Get Command in Linux


Every Linux user knows how critical apt-get commands are. From the very first time you install Ubuntu (or a similar Linux distribution), you come across this powerful tool.

This tutorial serves as a good introduction for beginners on the apt-get command. It can also help more experienced users refresh their memory and improve their knowledge of terminal commands.

How to use the apt-get command in Linux tutorial.

What Is apt-get and What Is It Used For?

apt-get is a command line tool for interacting with the Advanced Package Tool (APT) library (a package management system for Linux distributions). It allows you to search for, install, manage, update, and remove software.

The tool does not build software from the source code. Instead, it compiles the source code or uses precompiled files to install software packages.

Along with apt-get, there is also the apt utility. To learn more about these commands check out the article on APT vs APT-GET differences.

Note: All these commands, except the apt-cache (search) command, only work within root or superuser (sudo) privileges.

apt-get Syntax

The main syntax for using apt-get commands is:

apt-get [option] [command]

How to Use apt-get Command in Linux

Below you will find how to use the apt-get command to work with packages and software on your Linux system. Read through the list to learn more about the possibilities of apt-get.

How to Update or Upgrade Using apt-get

Before you install a package, it is crucial to resynchronize the package index files and update the package repository to the latest version. This ensures that the packages you install are up-to-date.

Update the package repository by running the command:

apt-get update
Use the apt-get command to update the package repository.

To update the package cache and checks for broken dependencies:

apt-get check

To upgrade all installed packages, use the apt-get command:

apt-get upgrade

Upgrade a specific package by running:

apt-get upgrade [package_name]

Search for dependencies with newer versions, install new packages, and remove old ones automatically:

apt-get dist-upgrade

Note: Be careful when using dist-upgrade as it may remove some packages you still need on your system.

To follow the changes made to the Status field of available packages by the traditional Debian packaging tool dselect and perform actions necessary to realize that state, use the command:

apt-get dselect-upgrade

How to Install Packages with apt-get

To install a package using apt-get, type in the following command:

apt-get install [package_name]

Replace [package_name] with the name of the software package you intend to install. If you do not know the exact name of the package, type in the first few letters and press TAB. The system will suggest all the packages available, starting with those letters.

Install package on Linux using the apt-get command.

To install a specific version of a package, run:

apt-get install [package_name]=[version_number]

Before the system installs the package, you will receive an output showing:

  • The additional packages required for the installation to be successful.
  • The package you intend to install.
  • The packages that must be upgraded.
  • How much disk space the package will use.

For example, if you want to install curl, you will receive the output as in the image below:

Install a specific version of a package using apt-get.

Finally, it will ask you whether you wish to continue with the installation. To answer, you must type in y for yes or n for no.

Confirm the apt-get installation of a specific version of a package.

To install multiple packages at the same time with a single command:

apt-get install [package_name1] [package_name2] [package_name3]

If you have packages with many reverse dependencies and you need the most up-to-date versions, use the apt-get reinstall command.

To download a package with all required dependencies without installing by running:

apt-get install --download-only [package_name]

How to Remove Packages with apt-get

To remove a package use the command:

apt-get remove [package_name]

However, this command only removes the package, leaving its configuration files on the system.

To remove the package along with its configuration files, use the command:

apt-get purge [package_name]

To clean the local repository of retrieved package files, use the command:

apt-get clean

The clean command removes everything except the local file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.

Another way to empty the local repository of retrieved files is to use autoclean and clear out packages that are no longer available:

apt-get autoclean

To remove the unnecessary packages that apt-get automatically installs to satisfy dependencies for other packages, run the command:

apt-get autoremove

How to Use apt-get Options

The apt-get command is modified by adding one or more options to the syntax.

apt-get [options] [command]

Below you will find a list of all commonly used apt-get options.

  • --no-install-recommends – only install main dependencies, do not include recommended packages
  • --install-suggests – install suggested packages as dependencies
  • -d/--download-only – download the packages without installing or unpacking them
  • -f/--fix-broken – attempt to correct a system with broken dependencies
  • -m/--ignore-missing/--fix-missing – ignore packages that cannot be retrieved
  • --ignore-hold – ignore packages placed on hold
  • --no-download – disable downloading packages
  • -q/--quiet – omit progress indicators and produce output suitable for logging
  • -s/--simulate/--just-print/--dry-run,--recon,--no-act – simulate events that would occur without actually change the system
  • -y/--yes/--assume-yes – assume “yes” as an answer to prompts
  • --assume-no – assume “no” as an answer to all prompts
  • --no-upgrade – do not upgrade packages (usually used with the install command to instruct apt-get not to upgrade if the package is already installed)
  • --only-upgrade – upgrade only installed packages
  • -V/--verbose-versions – display full versions of upgraded and installed packages
  • --show-progress – display progress bar while installing, removing or upgrading packages
  • >-b/--compile/--build – compile source packages once downloaded
  • --only-upgrade – upgrade only installed packages
  • --reinstall – reinstall installed packages to the newest version
  • --auto-remove/--autoremove – remove unnecessary packages while installing a package
  • -h/--help – display a short usage summary
  • -v/--version – display the version of apt-get
  • -c/--config-file – specify which configuration file to read after the default one
  • -o/--option – set an arbitrary configuration option

You can also define custom options by modifying the configuration file.


In this article, you learned the most common apt-get and apt-cache commands. These commands are simple to use and easy to remember.

Once you have mastered the use of each command, you can manage all your packages with ease and confidence.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !