The “apt-get” Command in Linux [10 Practical Examples]

The Advanced Package Utility (APT) library may be accessed via the command line tool apt-get (a package management system for Linux distributions). You may use the apt-get command in Linux to find, install, manage, update, and uninstall applications. Software is not created using the tool from the source code. Instead of using precompiled files or the source code, it builds software packages.

A. Description

The command-line tool for managing packages is apt-get, and it serves as the user’s “back end” for other programs that utilize the APT library.

B. Syntax

The apt-get command in Linux is a built-in command that takes options and commands as its argument. The main syntax for using apt-get commands is:

apt-get [OPTION] [COMMAND]
Note: In the above syntax, OPTION and COMMAND are enclosed by a square bracket.

C. Options

One or more options are added to the syntax of the apt-get command to modify the command. I have listed some useful options below. If you do not find your desired option here, you will find it on the man (manual) page. To go man page, type the following command and press ENTER.

man apt-get

Useful Options

  • –auto-remove or –autoremove : (When using apt-get with the install or remove command, this option acts like running the autoremove command.)
  • -d or –download-only: (with this option the user specifies that apt-get should only retrieve the packages, and not unpack or install them.)
  • -f or –fix-broken: (with this option, the user specifies that apt-get should attempt to correct the system with broken dependencies in place.)
  • -h or –help (displays a short usage summary.)
  • –no-install-recommends: (with this option, the user lets apt-get know not to consider recommended packages as a dependency to install.)
Note: All of the options are case-sensitive. You must be careful while using these.

Practical Examples of the “apt-get” Command in Linux

The apt-get command in Linux is helpful for finding, installing, managing, updating, and uninstalling applications. A few real-life examples of the apt-get command are given below.

Example 1: Update The Package Repository Using the “apt-get” Command in Linux

While we use Linux, it is essential to resynchronize the package index files and update the package repository before installing a package. By doing this, you can be confident the packages you install are the latest. Here, I will perform an update operation. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

apt-get update

➌ Now, press the ENTER button.
Output >
In the following image, we can see this command has resynchronized the package index files and updated the package repository.updating the package running apt-get update command


Similar Readings


Example 2: Install Packages Using the “apt-get” Command in Linux

While working in Linux, various packages are needed to be installed. Here, I will install the nano package. To do so, you can follow the below procedure.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

sudo apt-get install nano

➌ Now, press the ENTER button.

Output >

In the following image, we can see this command has installed the nano package.installing nano package running sudo apt-get install nano command

Example 3: Remove Packages Using the “apt-get” Command in Linux

While working, various packages are needed to be removed. Here, I will remove the nano package. To do so, you can follow the below procedure.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

sudo apt-get remove nano

➌ Now, press the ENTER button.

Output >

In the following image, we can see this command has removed the nano package.removing nano package running sudo apt-get remove nano command


Similar Readings


Example 4: Remove The Configuration Files of a Packages Using the “apt-get” Command in Linux

However, the apt-get remove command of the previous example only removes the package, leaving its configuration files on the system. Here I will remove the package and its configuration files both using the apt-get command followed by purge. To do so, follow the procedure below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

sudo apt-get purge nano

➌ Now, press the ENTER button.

Output >

In the following image, we can see this command has removed configuration files of the nano package.removing configuration files of the nano package running sudo apt-get purge nano command

Example 5: Upgrade All Installed Packages Using the “apt-get” Command in Linux

The apt-get command followed by upgrade is a very handy command in Linux to upgrade packages. Here I will upgrade all the installed packages. To do so, follow the procedure below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

sudo apt-get upgrade

➌ Now, press the ENTER button.

Output >

In the following image, we can see this command has upgraded all the packages installed. upgrading all the packages installed running sudo apt-get upgrade command


Similar Readings


Example 6: Full Upgrading Using the “apt-get” Command in Linux

The apt-get upgrade command of the previous example can not remove installed programs to upgrade the entire system. The apt-get command followed by full-upgrade can remove installed programs to upgrade the entire system. Here I will upgrade the entire system. To do so, follow the procedure below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

sudo apt-get full-upgrade

➌ Now, press the ENTER button.

Output >

In the following image, we can see this command has upgraded all the packages installed, removing the installed packages if needed to upgrade the whole system. upgrading all the packages installed, removing the installed packages if needed to upgrade the whole system running sudo apt-get full-upgrade command

Example 7: Remove Unused Packages Using the “apt-get” Command in Linux

The system will also install the package dependencies if a new package that depends on another item is installed. The dependencies will remain on the system even after the package is removed. These unused packages can be deleted since they are no longer required by anything else. Here, I will remove the unneeded dependencies. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

sudo apt-get autoremove

➌ Now, press the ENTER button.

Output >

In the following image, we can see this command has removed all the unneeded dependencies.removing all the unneeded dependencies running sudo apt-get autoremove command


Similar Readings


Example 8: Display Short Usage Summary Using the “apt-get” Command in Linux

Whenever it is necessary to display short usage summary, you can do it easily by using the apt-get command accompanied by the -h option. To display short usage summary, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo apt-get -h

➌ Now, press the ENTER button.

Output >

In the following image, we can see this command has displayed short usage summary.displaying short usage summary running sudo apt-get -h command

Example 9: Download A Package Using the “apt-get” Command in Linux

When downloading a package, you can do it easily by using the apt-get command. Here I will download the nano package. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

apt-get download nano

➌ Now, press the ENTER button.

Output >

In the following image, we can see that It has downloaded the nano package.downloading the nano package running apt-get download nano command


Similar Readings


Example 10: Clear Out the Local Repository of Retrieved Package Files Using the “apt-get” Command in Linux

The apt-get command also clears out the local repository of retrieved package files. It removes everything but not the lock file from /var/cache/apt/archives/partial/ and /var/cache/apt/archives/. Here I will use the apt-get command to clear out the local repository of retrieved package files. To do so, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt.

sudo apt-get clean

➌ Now, press the ENTER button.

Output >

In the following image, we can see that It has cleared out the local repository of retrieved package files.

clearing out the local repository of retrieved package files running sudo apt-get clean command

Conclusion:

In this article, I have tried to demonstrate the applications and effectiveness of the apt-get command in Linux. I hope you’ll be competent enough to explore more things with the help of these practical examples and find, install, manage, update, and uninstall the applications you need.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Susmit Das Gupta

Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio

Leave a Comment