If you are a Linux user, you might be well aware of the apt and apt-get commands with the most common option apt install. Apt is a powerful package management tool that can be used to search, install, update, upgrade, and manage the packages in a Linux operating system. It is a command-line-based tool that is preferred by most system administrators and users.

This article shows how to use the apt-get command for installing programs from the command line in Debian OS.

We have used Debian 10 OS for running the commands and procedure mentioned in this article. The same commands will work on Debian-based distributions like Ubuntu and its derivates as Kubuntu and Linux Mint too.

Using apt for installing programs

We will take the example of VLC player for installation using the apt-get command in the command line Terminal application. To open the Terminal, go to the Activities tab on the top left corner of the desktop. Then in the search bar, type terminal. When the Terminal icon appears, click on it to open.

Before installing the software, make sure you have the required software in the repositories of your OS. If it is not already present, you will have to add the additional repository to your sources.list.

Step 1: Add repository

Follow the below steps in order to add the repository to your system.

Enter the following command in Terminal to edit the “sources.list” file.

$ sudo nano /etc/apt/sources.list

Now add the entries in the file using the following syntax:

deb http://site.example.com/debian distribution component1 deb-src

deb-src http://site.example.com/debian distribution component1

For instance, in order to add the repository for VLC player, we have added the following entries:

deb http://deb.debian.org/debian/ unstable main contrib non-free

deb-src http://deb.debian.org/debian/ unstable main contrib non-free

Edit sources list file

Once done, press Ctrl+O to save and Ctrl+X to exit the nano editor.

Step 2: Update sources

Now after adding the repository, you will need to update your package list. To do so, enter the following command in Terminal:

$ sudo apt-get update

When prompted for the password, enter the sudo password.

Step 3: Install a package using apt-get using apt-get install

Now you can install the package from the updated repository. Use the following syntax in Terminal in order to install the packages using apt-get command:

$ sudo apt-get install package-name-1 package-name-2 package-name-3

You can use the above command to install just one package or multiple packages at once. Replace the package-name with your desired package name. If you do not remember the exact package name, just type initial letters and press tab to auto-complete them.

For instance, to install VLC player, the command would be:

$ sudo apt-get install vlc

apt get install

apt install vs. apt-get install

The traditional way to install programs using apt is to use the command ‘apt-get’ with the install option. Nowadays, the short form is more and more used. So instead of using

$sudo apt-get install <program name>

you can also use just:

$sudo apt install <program name>

Note: <program name> is just a placeholder for the .deb package name that you want to install. Multiple packages can be separated by white space.

Step 4: Verify installation

You can verify if the application is installed by viewing it in the list of all installed packages. To do so, run the following command in Terminal:

$ sudo dpkg --list

After installation, you can launch the application via Terminal or via the system application’s menu.

To make it easier to find the right package, combine the command with grep to search for the package name. Example:

$ sudo dpkg --list | grep <package name>

replace <package name> with the name of the .dpkg package that you are searching for.

Use apt to upgrade packages

You can also upgrade the packages to their latest available versions using the apt-get command.

Use the following command syntax in order to upgrade the packages:

$ sudo apt-get upgrade package-name-1 package-name-2 package-name-3

To upgrade all packages, you can use the following syntax:

$ sudo apt-get upgrade

Remove packages

In case you want to remove the installed packages using the apt-get command, you can do so by using the following syntax:

$ sudo apt-get remove vlc

Remove package using apt

The system will provide you with Y/n option to confirm the removal process. Press y to continue and the package will be removed from the system. However, note that this will only remove the package but not the configuration files. In order to remove the configuration files too, use the following command:

$ sudo apt-get purge package_name

In this article, we have learned the use of apt-get command for installing packages in a Debian system. Using the apt command line for installing and managing packages saves a lot of time. It also comes in handy when you are accessing and performing the installation on a remote system via SSH. There is also a guide on using apt on Ubuntu.

How to use apt to install programs from command line in Debian
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn