When you begin to use the Ubuntu operating system, the first choice of installing software is through the graphical Ubuntu Software manager. Although many programs are available in this collection, you will soon know that it lacks many powerful utilities especially that for the command line. Then is the time to switch to the more powerful software installation utility, the apt-get. Not only you can install software in the command line through this utility, but you can also:

  • Update the package repositories
  • Update installed software
  • Search for available packages
  • Get the source code for an installed package
  • Reinstall a software package
  • Remove a software from your system

In this article, we will explain how to use the apt-get utility in order to perform the above-listed operations.

We have run the commands and procedures mentioned in this article on an Ubuntu 18.04 LTS system. Since apt-get is a command line utility, we will be using the Ubuntu Terminal for that. You can open the Terminal either through the system Dash or the Ctrl+alt+T shortcut.

Update the Package Repositories with apt

A repository is a list of available software packages in a given snapshot in time. Since the packages in this list are sometimes added, removed and updated, you need to update your system repositories from time to time. This will enable you to have an updated list of all the available software packages of the repository.

It is best to update the repositories before installing a new software by running the following command as root:

$ sudo apt-get update

Update package lists

Now your system repositories are in-line with those on the Internet.

Update Installed Software with apt

Although you can use the update manager in order to update installed software on your system. The apt-get utility also provides a way to do the same. Use the following command as root in order to upgrade software on your system:

$ sudo apt-get upgrade

Update installed software

Now the software on your system is up to date.

Search for Available Packages with apt

In order to search for available packages from the Internet repositories, you can use the apt-cache utility. Use the following syntax to do so:

$ sudo apt-cache search [package name keyword]

Example:

Let us search for the stable version of the Opera web browser through the following apt-cache command:

$ sudo apt-cache search "opera-stable"

The following output shows the availability of ‘opera-stable’ package for the web browser.

Search for Ubuntu packages

You can get detailed information about the package through the following apt-cache command:

Syntax:

$ sudo apt-cache show “package-name”

Example:

$ sudo apt-cache show "opera-stable"

The following output shows detailed about the ‘opera-stable’ package:

Get detailed package information with apt

Install a Package with apt

Here comes the most famous use of the apt-get command; installing software from an updated repository.

Use the following command as root in order to install a software package:

$ sudo apt-get install “package-name”

Example:

You can install the stable version of the Opera web browser by installing the package, that we searched above, as follows:

$ sudo apt-get install opera-stable

Install package with apt package manager

The system prompts you with a y/n solution before installing a program through the apt-get utility. Always enter Y to proceed with the installation.

Get the Source Code for an Installed Package with apt

If you want the source code for an installed package, you can use the following command :

Syntax:

$ sudo apt-get source “package-name”

Example:

For example, if I want to get the source code of the opera-stable package that I just installed, I will use the following command:

$ sudo apt-get source opera-stable

If you get this error after running the above command:

E: You must put some ‘source’ URIs in your sources.list

You need to remove the commenting from the deb-src line for the respective package from the sources.list file. This file is located in /etc/apt/ folder.

You can open the sources file in the nano editor through the following command:

$ sudo nano sources.list

Edit sources.list file

Press Ctrl+X and then Y for exiting and then saving the changes.

Reinstall a Software Package with apt

While running an application, it might stop working or go corrupt. In that case, you can easily reinstall that application through the apt-get command as follows:

$ sudo apt-get install “package-name” –reinstall

Example:

$ sudo apt-get install opera-stable --reinstall

This command will re-install the Opera browser that was already installed on my system.

Reinstall software

Remove a Software from Your System

When you want to remove a software from your system, you can use the following apt-get command:

$ sudo apt-get remove “package-name”

Example:

$ sudo apt-get remove opera-stable

This command will remove the Opera web browser from my system

Removae software package by using apt

Remove Complete Software Configurations

The apt-get remove command removes the software from your system but it does not remove the configuration files that might have been installed with it. The following command will completely remove those configuration files for a software:

$ sudo apt-get purge “package-name”

Example:

$ sudo apt-get purge opera-stable

This command will completely remove Opera configurations from my system.

use apt-get purge

The system prompts with a Y/n option for removing or purging a software; always enter Y to proceed with software removal.

In this tutorial, we have seen how the apt-get command can be utilized for not only installing software on your system but also performing all installation-related tasks. Now you do not need to solely depend on the Ubuntu Software manager in order to install programs on your system.

How to use apt Package Manager on Ubuntu Command Line