When you initially start using the Ubuntu Operating System, the graphical Ubuntu Applications Manager is your first choice for installing software. Despite the fact that this collection contains a large number of applications, you will quickly discover that it lacks many strong tools, particularly those for the command line. Then it’s time to move to apt-get, a more capable software installation tool. You may use this tool to not only install software from the command line, but also to:
- 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 post, we’ll show you how to use the apt-get tool to complete the tasks indicated above.
On an Ubuntu 20.04 LTS system, we ran the tools and processes described in this article. We’ll use the Ubuntu Terminal to run apt-get because it’s a command-line utility. The Terminal may be accessed using the system Dash or the CTRL+ALT+T shortcut.
What is apt-get?
Advanced Package Tool, or APT, is a free-software user interface that works with core libraries to handle the installation and removal of software on Debian, Ubuntu, and related Linux distributions. APT simplifies the process of managing software on Unix-like computer systems by automating the retrieval, configuration and installation of software packages, either from precompiled files or by compiling source code.
Update the Package Repositories with apt-get
A repository is a catalog of software programs that are available at a specific point in time. Because the packages in this list are added, deleted, and changed on a regular basis, you should keep your system repositories up to date. This will provide you with an up-to-date list of all the repository’s accessible software packages.
Before installing new software, it’s a good idea to update the repositories by executing the following command:
$ sudo apt-get update
Now your system repositories are in-line with those on the Internet.
Update Installed Software with apt-get
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
Now the software on your system is up to date.
Search for Available Packages with apt-get
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]
Let us search for the stable version of the Opera web browser through the following apt-cache command:
$ sudo apt-cache search ffmpeg
The following output shows the availability of ‘ffmpeg’ package for the Tools for transcoding, streaming and playing of multimedia files.
You can get detailed information about the package through the following apt-cache command:
$ sudo apt-cache show “package-name”
$ sudo apt-cache show ffmpeg
The following output shows detailed about the ‘ffmpeg’ package:
Install a Package with apt-get
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”
You can install the stable version of the FFmpeg by installing the package, that we searched above, as follows:
$ sudo apt-get install ffmpeg
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-get
If you want the source code for an installed package, you can use the following command :
$ sudo apt-get source “package-name”
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 ffmpeg
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 /etc/apt/sources.list
Press CTRL+O to write change then press CTRL+X for exit.
Then run following command to update the apt cache
$ sudo apt-get update
Now run the command to get the source again but it will throw an error with a question
sh: 1: dpkg-source: not found Unpack command 'dpkg-source -x ffmpeg_4.2.4-1ubuntu0.1.dsc' failed. Check if the 'dpkg-dev' package is installed. E: Sub-process dpjg-source returned an error code (1)
To fix this error simply install dpkg-dev package from apt by running the following command
$ sudo apt-get install dpkg-dev
Finally you will be able to get the source code of required software with following command
$ sudo apt-get source ffmpeg
Reinstall a Software Package with apt-get
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
$ sudo apt-get install ffmpeg --reinstall
This command will re-install the Opera browser that was already installed on my system.
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”
$ sudo apt-get remove ffmpeg
This command will remove the Opera web browser from my system
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”
$ sudo apt-get purge ffmpeg
This command will completely remove Opera configurations from my system.
When uninstalling or purging software, the system will provide you with a Y/n choice; always select Y to proceed with program removal.
We’ve shown how to use apt-get command to not only install software on your system but also to execute all installation-related activities in this article. You no longer have to rely exclusively on the Ubuntu Software Manager to install apps on your computer.