How to install apt to ubuntu
How to install apt to ubuntu
Package Management
Ubuntu features a comprehensive package management system for installing, upgrading, configuring, and removing software. In addition to providing access to an organized base of over 60,000 software packages for your Ubuntu computer, the package management facilities also feature dependency resolution capabilities and software update checking.
Several tools are available for interacting with Ubuntu’s package management system, from simple command-line utilities which may be easily automated by system administrators, to a graphical interface which is easy to use by those new to Ubuntu.
Introduction
Ubuntu’s package management system is derived from the same system used by the Debian GNU/Linux distribution. The package files contain all of the necessary files, meta-data, and instructions to implement a particular functionality or software application on your Ubuntu computer.
The apt command is a powerful command-line tool, which works with Ubuntu’s Advanced Packaging Tool (APT) performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu system.
Some examples of popular uses for the apt utility:
Install a Package: Installation of packages using the apt tool is quite simple. For example, to install the nmap network scanner, type the following:
Remove a Package: Removal of a package (or packages) is also straightforward. To remove the package installed in the previous example, type the following:
Multiple Packages: You may specify multiple packages to be installed or removed, separated by spaces.
Update the Package Index: The APT package index is essentially a database of available packages from the repositories defined in the /etc/apt/sources.list file and in the /etc/apt/sources.list.d directory. To update the local package index with the latest changes made in the repositories, type the following:
Upgrade Packages: Over time, updated versions of packages currently installed on your computer may become available from the package repositories (for example security updates). To upgrade your system, first, update your package index as outlined above, and then type:
For information on upgrading to a new Ubuntu release see Upgrading.
Actions of the apt command, such as installation and removal of packages, are logged in the /var/log/dpkg.log log file.
For further information about the use of APT, read the comprehensive APT User’s Guide or type:
Aptitude
Launching Aptitude with no command-line options will give you a menu-driven, text-based front-end to the Advanced Packaging Tool (APT) system. Many of the common package management functions, such as installation, removal, and upgrade, can be performed in Aptitude with single-key commands, which are typically lowercase letters.
Aptitude is best suited for use in a non-graphical terminal environment to ensure proper functioning of the command keys. You may start the menu-driven interface of Aptitude as a normal user by typing the following command at a terminal prompt:
When Aptitude starts, you will see a menu bar at the top of the screen and two panes below the menu bar. The top pane contains package categories, such as New Packages and Not Installed Packages. The bottom pane contains information related to the packages and package categories.
Using Aptitude for package management is relatively straightforward, and the user interface makes common tasks simple to perform. The following are examples of common package management functions as performed in Aptitude:
Install Packages: To install a package, locate the package via the Not Installed Packages package category, by using the keyboard arrow keys and the ENTER key. Highlight the desired package, then press the + key. The package entry should turn green, indicating that it has been marked for installation. Now press g to be presented with a summary of package actions. Press g again, and downloading and installation of the package will commence. When finished, press ENTER, to return to the menu.
Update Package Index: To update the package index, simply press the u key. Updating of the package index will commence.
Upgrade Packages: To upgrade packages, perform the update of the package index as detailed above, and then press the U key to mark all packages with updates. Now press g whereby you’ll be presented with a summary of package actions. Press g again, and the download and installation will commence. When finished, press ENTER, to return to the menu.
The first column of the information displayed in the package list in the top pane, when actually viewing packages lists the current state of the package, and uses the following key to describe the state of the package:
i: Installed package
c: Package not installed, but package configuration remains on the system
p: Purged from system
v: Virtual package
B: Broken package
u: Unpacked files, but package not yet configured
To exit Aptitude, simply press the q key and confirm you wish to exit. Many other functions are available from the Aptitude menu by pressing the F10 key.
Command Line Aptitude
You can also use Aptitude as a command-line tool, similar to apt. To install the nmap package with all necessary dependencies, as in the apt example, you would use the following command:
To remove the same package, you would use the command:
Consult the man pages for more details of command-line options for Aptitude.
dpkg is a package manager for Debian-based systems. It can install, remove, and build packages, but unlike other package management systems, it cannot automatically download and install packages or their dependencies. Apt and Aptitude are newer, and layer additional features on top of dpkg. This section covers using dpkg to manage locally installed packages:
To list all packages in the system’s package database, including all packages, installed and uninstalled, from a terminal prompt type:
Depending on the number of packages on your system, this can generate a large amount of output. Pipe the output through grep to see if a specific package is installed:
Replace apache2 with any package name, part of a package name, or a regular expression.
To list the files installed by a package, in this case the ufw package, enter:
The output shows that the /etc/host.conf belongs to the base-files package.
Uninstalling a package can be accomplished by:
APT Configuration
Configuration of the Advanced Packaging Tool (APT) system repositories is stored in the /etc/apt/sources.list file and the /etc/apt/sources.list.d directory. An example of this file is referenced here, along with information on adding or removing repository references from the file.
You may edit the file to enable repositories or disable them. For example, to disable the requirement of inserting the Ubuntu CD-ROM whenever package operations occur, simply comment out the appropriate line for the CD-ROM, which appears at the top of the file:
Extra Repositories
In addition to the officially supported package repositories available for Ubuntu, there exist additional community-maintained repositories which add thousands more packages for potential installation. Two of the most popular are the universe and multiverse repositories. These repositories are not officially supported by Ubuntu, but because they are maintained by the community they generally provide packages which are safe for use with your Ubuntu computer.
Packages in the multiverse repository often have licensing issues that prevent them from being distributed with a free operating system, and they may be illegal in your locality.
Be advised that neither the universe or multiverse repositories contain officially supported packages. In particular, there may not be security updates for these packages.
Many other package sources are available, sometimes even offering only one package, as in the case of package sources provided by the developer of a single application. You should always be very careful and cautious when using non-standard package sources, however. Research the source and packages carefully before performing any installation, as some package sources and their packages could render your system unstable or non-functional in some respects.
By default, the universe and multiverse repositories are enabled but if you would like to disable them edit /etc/apt/sources.list and comment the following lines:
Automatic Updates
The unattended-upgrades package can be used to automatically install updated packages and can be configured to update all packages or just install security updates. First, install the package by entering the following in a terminal:
To configure unattended-upgrades, edit /etc/apt/apt.conf.d/50unattended-upgrades and adjust the following to fit your needs:
Certain packages can also be excluded and therefore will not be automatically updated. To block a package, add it to the list:
The double “//” serve as comments, so whatever follows “//” will not be evaluated.
To enable automatic updates, edit /etc/apt/apt.conf.d/20auto-upgrades and set the appropriate apt configuration options:
However, it may happen that if the server is off at the time the timer unit elapses, the timer will be triggered immediately at the next startup. As a result, they will often run on system startup
and thereby cause immediate activity and hold the apt-lock.
In many cases that is beneficial, but in some cases it might be counter-productive. Examples are administrators with many shut down machines or VM images that are only started for some quick action that then is delayed or even blocked by the unattended upgrades. To adapt this behaviour, we can change/override the configuration of both apt’s timer units [ apt-daily-upgrade.timer, apt-daily.timer ]. To do so use systemctl edit and override the Persistent attribute like Persistent=delay (example of such an override):
The local download archive is cleaned every week. On servers upgraded to newer versions of Ubuntu, depending on your responses, the file listed above may not be there. In this case, creating a new file of this name should also work.
You can read more about apt Periodic configuration options in the apt.conf(5) manpage and in the /usr/lib/apt/apt.systemd.daily script header.
Notifications
Configuring Unattended-Upgrade::Mail in /etc/apt/apt.conf.d/50unattended-upgrades will enable unattended-upgrades to email an administrator detailing any packages that need upgrading or have problems.
Another useful package is apticron. apticron will configure a cron job to email an administrator information about any packages on the system that have updates available, as well as a summary of changes in each package.
To install the apticron package, in a terminal enter:
References
Most of the material covered in this chapter is available in man pages, many of which are available online.
The InstallingSoftware Ubuntu wiki page has more information.
For more dpkg details see the dpkg man page.
The APT User’s Guide and apt man page contain useful information regarding apt usage.
For more info about systemd timer units (and systemd in general), visit systemd man page and systemd.timer man page.
See the aptitude user’s manual for more aptitude options.
The Adding Repositories HOWTO (Ubuntu Wiki) page contains more details on adding repositories.
Ubuntu Documentation
Introduction
Note: The Main page is available in multiple languages.
Installing software in Ubuntu is easy, and this guide will show you how to do it.
By default, many useful programs are already installed when you put Ubuntu onto your computer. However, you may need a particular piece of software that serves a purpose not served by the default applications. You might just want to try an alternative program to one which is already installed. In other words, you need new software.
If you’d like to get some background information on what’s happening when you install software (which can sometimes be technical), read Packages and Package Management. If you just want to get started installing new programs, you can skip straight to Installing a Package.
Packages and Package Management
This section covers the basic concepts of packages and package management. You will learn about what a package is, the differences between different types of package and also how package management works on Ubuntu.
What is a package?
Software is a very broad term, and is generally taken to mean a program which you can run on your computer. However, such programs often need other resources to work. When you install software, thousands of files may be required just to let the program start! When you think that they all have to be put in exactly the right location, and some of those files may need to be changed depending on what type of computer you have, it can all get very complicated. Luckily, Ubuntu can look after this complexity.
Ubuntu uses packages to store everything that a particular program needs to run. A ‘package’, then, is essentially a collection of files bundled into a single file, which can be handled much more easily. In addition to the files required for the program to run, there will be special files called installation scripts, which copy the files to where they are needed (amongst other things).
Source or Binary?
Normally, when someone makes a package for a program, they put all of the source code for the program into that package. Source code is written by programmers and is essentially a list of instructions to a computer which humans are able to read and write. Computers can only understand this code if it is interpreted for them into a form that they can use directly. One such way of interpreting source code for a computer is by translating or compiling it into binary, which computers can understand.
So why don’t the people who make the package (called packagers) just convert it into binary from the start? Well, different computers use different types of binary, so if you make a binary package for one type (like an Intel PC), it won’t work on another (like a PowerPC).
Package Dependencies
Programs often use some of the same files as each other. Rather than putting these files into each package, a separate package can be installed to provide them for all of the programs that need them. So, to install a program which needs one of these files, the package containing those files must also be installed. When a package depends on another in this way, it is known as a package dependency. By specifying dependencies, packages can be made smaller and simpler, and duplicates of files and programs are mostly removed.
An example of dependencies
Package Managers
A package manager is an application which handles the downloading and installation of packages. Ubuntu includes a few package managers by default, and which one you use depends on how advanced the package management tasks are that you want to achieve. Most people will only need to use the most basic package manager, the Add/Remove tool, which is very easy to use.
Software Channels/Repositories
Where can you get packages from?
Ubuntu stores all of its packages in locations called software channels or repositories. A software channel is simply a location which holds packages of similar types, which can be downloaded and installed using a package manager. A package manager will store an index of all of the packages available from a software channel. Sometimes it will ‘re-build’ this index to make sure that it is up to date and knows which packages have been upgraded or added into the channel since it last checked.
Installing a Package
This section explains how to install packages using the various tools available in Ubuntu,Xubuntu,Edubuntu and Kubuntu.
Via your web browser
In the Ubuntu Documentation, you will sometimes find sentences like for example:
» To install this software in Ubuntu, install the following package: supertux. «
if not, please follow instructions of the AptURL page to enable apturl protocol on your computer.
Via a basic graphical method
Note that some packages can’t be installed via this method, in this case please use another method.
for Ubuntu: «Sofware Centre «
In recent versions of Ubuntu, the «Add/Remove» option in the Applications menu has been replaced by the Ubuntu Software Center.
for Kubuntu : «Add/Remove Programs»
Kubuntu’s new and easy method of installing packages is to use the ‘Add/Remove Programs’ tool. Click K-Menu → Add/Remove Programs to start it.
Add/Remove Programs is a simple graphical way of installing and removing applications in Kubuntu. To launch Add/Remove Programs, choose K Menu → Add/Remove Programs from the desktop menu system.
To install new applications select the category on the left, then check the box of the application you want to install. When finished click Apply, then your chosen programs will be downloaded and installed automatically, as well as installing any additional applications that are required. The default selection is restricted to KDE suite, but GNOME applications can be installed simply by selecting from dropdown menu at the top. Alternatively, if you know the name of the program you want, use the Search tool at the top.
Software from additional repositories may be installed by enabling the Show: Unsupported and Show: proprietary software checkboxes if they are enabled in your repository list. For more information, see the Repositories page.
Once this has finished, click Close.Your new programs are installed, ready to use!
Via an advanced graphical method
for Ubuntu/Xubuntu/Edubuntu : Synaptic
The Synaptic Package Manager offers a more advanced way of installing packages. If you have problems finding a suitable package with the Add/Remove tool, try using the search in Synaptic. This searches all of the packages in the available repositories, even the ones which don’t contain programs.
For details on using Synaptic, see SynapticHowto.
Via a Text Based Methods
Text based methods can be used across Ubuntu, Kubuntu and Xubuntu, but require familiarity with the terminal. When helping users to install packages, you should consider using an AptURL instead of apt-get or aptitude.
Aptitude is a text-based package manager, which must be run from a Terminal. Read the AptitudeSurvivalGuide for more information on how to use Aptitude.
The apt-get program is a command-line package manager, which should be used if the Add/Remove tool and Synaptic ever run into problems. It provides an advanced interface to APT, the underlying package management system which Ubuntu uses, but is reasonably easy to operate. Power users may find that apt-get is quicker to use and more powerful than the graphical options above.
For details on how to use apt-get, read AptGet/Howto.
Installing downloaded packages
You may wish to install a package you have downloaded from a website, rather than from a software repository. These packages are called .deb files. Because they may have been created for a different Linux distribution, you might find that there’s dependency issues with Ubuntu, meaning that they may not be installable.
To find a package which you have previously downloaded using Synaptic, aptitude or apt-get, look in /var/cache/apt/archives
Using GDebi to install packages
Once you have installed GDebi, use the File Browser to find the package you wish to install. Package files will look similar to this:
Double-click the package to open it with GDebi. If all dependencies have been met for the selected package, simply click the ‘Install package’ button to install it. GDebi will warn you if there are unmet dependencies, which means that there’s dependencies that aren’t resolved in the repositories that you’re using.
Using dpkg to install packages
dpkg is a command-line tool used to install packages. To install a package with dpkg, open a Terminal and type the following:
Note: replace directory with the directory in which the package is stored and package_name with the filename of the package.
It is recommended that you read the dpkg manual page before using dpkg, as improper use may break the package management database. To view the manual page for dpkg, open a Terminal and type man dpkg.
Getting a list of recently installed packages
You can use the dpkg logs to discover recently installed packages; this is handy if you want to roll back some recent installations to a previous system state.
More detailed information on this can be found here.
Automatic updates: Update Manager
Ubuntu will automatically notify you when security updates and software upgrades are available. The Ubuntu Update Manager is a simple and easy to use application that helps users to keep their system software updated. Simply click the update icon (which will appear in the notification area), type in your super-user/administrator password and follow the instructions on-screen to download and install the updates.
Keeping up to date is important, as security fixes which protect your computer from harm are delivered in this way.
Installing packages without an Internet connection
Sometimes, an internet connection is unavailable to install programs.
It is possible to install programs without CDs or DVDs onto offline computers, using a simple USB key for example to transfer only the packages you need.
There are several methods to do this:
Use Keryx
Keryx is a portable, cross-platform package manager for APT-based (Ubuntu, Debian) systems. It provides a graphical interface for gathering updates, packages, and dependencies for offline computers. Keryx is free and open source. You can get Keryx here: https://launchpad.net/keryx
Use the Synaptic package download script
Note: If you don’t have access to a PC with GNU/Linux or emulating/virtualizing GNU/Linux (Cygwin, VMware, VirtualBox, Qemu, etc), just open the script with a text editor and enter all the URLs you see in your browser to download the corresponding packages.
Use Offline apt-get update
If you can’t even select the packages on your offline PC because you can’t add the repository / update the package info, try this: AptGet/Offline/Repository
Basically, it consists in creating your own local repository, except that it won’t contain the packages themselves, only the dependency information.
The problem is that when you generate the package download list using this method, it will try to get the packages from your local repository and obviously fail.
The solution is to post-process the script by replacing the URLs with the correct one.
Assuming you created the local repository at «/home/username/repository» and got the different files from «http://archive.ubuntu.com/ubuntu/», this can easily be done with the following command:
or directly without creating a second script:
or simply with any text editor featuring search&replace.
Use apt-offline
apt-offline allows you to easily upgrade or install new packages on your offline PC, by using another online PC.
How to Use APT Package Manager in Ubuntu 20.04 LTS
Ubuntu Package Repositories:
Ubuntu package repositories are basically file servers where all the deb packages are kept.
Ubuntu has 4 main official package repositories: main, restricted, universe, and multiverse.
In main repository, Ubuntu supported free and open source softwares are kept.
In restricted repository, proprietary drivers (i.e. NVIDIA) are kept.
In universe repository, free and open-source softwares that are maintained by the community are kept.
In multiverse repository, softwares that have copyright restriction or legal issues are kept.
Ubuntu also has an extra package repository called partner. In partner repository, some proprietary and closed-source softwares are kept.
There are other third-party package repositories and PPAs which you can add on Ubuntu to install your desired software packages as well.
Ubuntu Package Repository Configuration Files:
Ubuntu package repository information is stored in the /etc/apt/sources.list file. Third-party PPAs and other repositories are stored as .list files in the /etc/apt/sources.list.d/ directory. There configuration files are plain text files. So, you can easily use a text editor to manage them.
The contents of the /etc/apt/sources.list file is shown in the screenshot below.
Here, each line starting with deb or deb-src is an APT package repository line. The lines starting with # (hash) are comments. They describe what the repository is for.
The APT package repository line has the following format:
Here, can be deb or deb-src.
deb is used to define repositories that contain compiled packages.
deb-src is used to define repositories that contain source codes of the packages which must be compiled before use.
deb-src is mainly used for development purposes. If you are not a software developer or don’t have any idea what this is, then just use deb.
is the location (i.e. http://us.archive.ubuntu.com/ubuntu/) where the packages are hosted. The APT package manager will download package information and package files from this location.
is the code name of the Ubuntu version you’re running.
You can find the code name of your Ubuntu machine with the following command:
In case of Ubuntu 20.04 LTS, the is focal.
There are also updates (i.e. focal-updates) for the Ubuntu official package repositories which keeps all the incremental updates of packages after the release of an Ubuntu version.
The is the name of the package repository. In case of the official Ubuntu package repositories, the is main, restricted, universe, and multiverse.
You can put one or more in the same APT package repository line separated by spaces (i.e. main restricted universe).
Here is an example of an APT package repository line:
Listing Enabled Package Repositories of Ubuntu:
You can list all the enabled package repositories of your Ubuntu operating system with the following command:
As you can see, all the enabled package repositories are displayed.
Managing Official Package Repositories:
By default, the Ubuntu official main, restricted, universe and multiverse package repositories are enabled. The partner repository is not enabled.
You can enable an Ubuntu official package repository (let’s say, restricted) with the following command:
As you can see, the restricted repository is already enabled. If it is disabled for some reason, it will be enabled.
You can disable or remove the official restricted repository as follows:
As you can see, the restricted repository is disabled.
Adding and Removing Ubuntu partner Repository:
You can add the Ubuntu partner repository with the following command:
The Ubuntu partner repository should be enabled.
As you can see, Ubuntu partner repository is enabled.
You can also remove the Ubuntu partner repository with the following command:
Managing Third-Party Package Repositories:
If the Ubuntu official package repositories do not have the software/tool you’re looking for, you can always add third-party package repositories and PPAs on Ubuntu and install your desired software/tool from there.
A good source of third-party Ubuntu PPAs is launchpad. Visit the Launchpad Ubuntu PPA page and search for the software/tool (i.e. codeblocks) you’re looking for there.
From the search results, you can find the third-party PPA repository of your desired software/tool. Click on the PPA link that you like. I have picked Codeblocks Daily Builds PPA for demonstration.
The PPA should have instructions on how to install things from the PPA as you can see in the screenshot below. Just follow the PPA specific installation instructions.
For example, Codeblocks Daily Builds PPA tells you to run 3 commands to install Codeblocks Daily build.
Here, the following command is used to add the PPA to your Ubuntu operating system:
The PPA should be added and also the APT package repository cache should be updated.
In my case, the PPA won’t work as it does not support Ubuntu 20.04 LTS yet. But it’s added.
As you can see, the PPA repository was added to my Ubuntu machine.
If you want, you can remove the PPA with the following command:
The PPA should be removed. As you can see, the PPA is no more in the /etc/apt/sources.list file or in /etc/apt/sources.list.d/ directory.
Some third-party software (i.e. Docker, MongoDB) may provide the APT package repository line which you can add on Ubuntu to install it.
For example, Docker’s official APT package repository line may look as follows:
Here, focal is the of Ubuntu 20.04 LTS.
To add this repository, run the following command:
The Docker official package repository should be added.
Ignore the errors. Docker does not support Ubuntu 20.04 LTS yet. I have only used it for the demonstration on how to add/remove third-party package repositories on Ubuntu.
As you can see, the Docker package repository is added.
To remove a third-party package repository, list all the enabled package repositories with the following command:
Then, copy the APT package repository line which you want to remove from the list.
Then, remove the third-part package repository as follows:
As you can see, the third-party package repository is not in the enabled package repository list anymore.
Updating Package Repository Cache:
Once you have added new APT package repositories, run the following command to update the APT package repository cache:
The APT package repository cache should be updated.
List Installed Packages:
You can list all the packages that are installed on your Ubuntu machine with the following command:
All the installed packages (i.e. acl, acpi-support), the package version (i.e. 2.2.53-6, 0.143), the package architecture (i.e. amd64) should be listed as you can see in the screenshot below. The list is very long.
Listing Upgradable Packages:
If you want to list the packages which are installed on your Ubuntu machine but a newer version (update) is available in the package repository, run the following command:
As you can see, all the packages that have updates (newer version) available are listed. I will show you how to install these updates in a later section of this article.
Searching for Packages:
You can search for packages by the package name, the package description and so on. You can use Regular Expressions for searching packages as well.
For example, you can search for all the available text editor packages as follows:
As you can see, the packages that matched search query text editor are listed. The list is very long. I have shown only a small portion of the list here.
Here, the green text represents the package name which you can use to install the package on your Ubuntu machine.
You can also use Regular Expressions to search for packages.
For example, you can search for packages that start with node- as follows:
If you’re interested to know more about any specific package (i.e. nodejs), you can run the following command:
As you can see, a lot of information on the nodejs package is displayed.
The Package name is nodejs.
The package Version is 10.19.0
The package is from web Section of the universe repository.
The package will use 158 KB of disk space once installed (Installed-Size).
It Depends on libc6 and libnode64 packages.
The Homepage of the project is http://nodejs.org.
The package Download-Size is 61.1 KB.
The package is from the http://us.archive.ubuntu.com/ubuntu focal/universe amd64 Packages repository (APT-Sources) etc.
What the package is for is described in the Description section.
There are a lot more information which you can read if you want
Installing Packages from the Enabled Package Repositories:
Once you have found the package or packages you want to install, you can easily install them on your Ubuntu machine.
You can install a single package (i.e. nodejs) as follows:
As you can see, installing this package will install 3 more dependency packages. In total 4 new packages will be installed. You will have to download about 6,807 KB of package files from the internet. Once the packages are installed, it will consume about 30.7 MB of additional disk space.
As you can see, the required packages are being downloaded from the internet.
At this point, the packages should be installed.
You can also install more than one packages (i.e. filezilla, apache2, vsftpd) at the same time as follows:
The required packages are being downloaded from the internet.
At this point, all the packages should be installed.
Installing Third-Party DEB Packages:
You can install a third-party DEB package (.deb) file on your Ubuntu machine using the APT package manager. If the third-party DEB package has any dependencies, the APT package manager will try to resolve them as well.
For example, I have downloaded Visual Studio Code DEB package file from the official website of Visual Studio Code. The DEB package file code_1.44.2-1587059832_amd64.deb is in the
/Downloads directory as you can see in the screenshot below.
Now, you can install the DEB package file code_1.44.2-1587059832_amd64.deb using the APT package manager as follows:
The DEB package file should be installed.
Installing Specific Package Version:
A package may have many versions in the package repository. You can install a specific version of that package if you want.
You can find all the available versions of a package (i.e. netplan.io) with the following command:
As you can see, 2 versions (0.99-0ubuntu2 and 0.99-0ubuntu1) of netplan.io package is available.
Now, you can install netplan.io version 0.99-0ubuntu2 as follows:
netplan.io version 0.99-0ubuntu2 should be installed.
The same way, you can install netplan.io version 0.99-0ubuntu1 as follows:
Uninstalling Packages:
You can uninstall a package very easily with the APT package manager.
You can uninstall a package (i.e. nodejs) as follows:
The package should be removed.
Even after you have removed a package (i.e. nodejs), the package may have left some configuration files and other files. You can remove these as well as follows:
The leftover files of the package (if it has any) should be removed.
Removing Unnecessary Packages:
Once you have removed a package, the dependency packages that were installed along with the package are no longer needed.
You can remove these unnecessary packages with the following command:
As you can see, 3 packages are no longer needed. Once they are removed, about 30.5 MB of disk space will be freed.
All the unnecessary packages should be removed.
Keeping Packages Up to Date:
I have covered this topic in a separate article. To learn how to keep all the packages of your Ubuntu machine up to date read my article How to Update Ubuntu 20.04 from the Command Line Interface.
Cleaning Up:
All the packages that the APT package manager downloads are cached in the /var/cache/apt/archives/ directory as you can see in the screenshot below.
To remove the cached packages, run the following command:
As you can see, the cached packages are removed.
So, this is how you use APT package manager in Ubuntu 20.04 LTS. Thanks for reading this article.
apt Command in Linux
Updated Feb 24, 2020
apt is a command-line utility for installing, updating, removing, and otherwise managing deb packages on Ubuntu, Debian, and related Linux distributions. It combines the most frequently used commands from the apt-get and apt-cache tools with different default values of some options.
apt is designed for interactive use. Prefer using apt-get and apt-cache in your shell scripts as they are backward compatible between the different versions and have more options and features.
Most of the apt commands must be run as a user with sudo privileges.
This guide serves as a quick reference for the apt commands.
Updating package index ( apt update ) #
The APT package index is basically a database that holds records of available packages from the repositories enabled in your system.
To update the package index run the command below. This will pull the latest changes from the APT repositories:
Always update the package index before upgrading or installing new packages.
Upgrading packages ( apt upgrade ) #
Regularly updating your Linux system is one of the most important aspects of overall system security.
To upgrade the installed packages to their latest versions run:
The command doesn’t upgrade packages that require removal of installed packages.
If you want to upgrade a single package, pass the package name:
Full Upgrading ( apt full-upgrade ) #
The difference between upgrade and full-upgrade is that the later will remove the installed packages if that is needed to upgrade the whole system.
Be extra careful when using this command.
Installing packages ( apt install ) #
Installing packages is as simple as running the following command:
If you want to install multiple packages with one command, specify them as a space-separated list:
To install local deb files provide the full path to file. Otherwise, the command will try to retrieve and install the package from the APT repositories.
Removing Packages ( apt remove ) #
You can also specify multiple packages, separated by spaces:
The remove command will uninstall the given packages, but it may leave some configuration files behind. If you want to remove the package including all configuration files, use purge instead of remove :
Remove Unused Packages ( apt autoremove ) #
Whenever a new package that depends on other packages is installed on the system, the package dependencies will be installed too. When the package is removed, the dependencies will stay on the system. This leftover packages are no longer used by anything else and can be removed.
To remove the unneeded dependencies use the following command:
Listing Packages ( apt list ) #
The list command allows you to list the available, installed and, upgradeable packages.
To list all available packages use the following command:
The command will print a list of all packages, including information about the versions and architecture of the package. To find out whether a specific package is installed, you can filter the output with the grep command.
To list only the installed packages type:
Getting a list of the upgradeable packages may be useful before actually upgrading the packages:
Searching Packages ( apt search ) #
This command allows you to search for a given package in the list of the available packages:
If found, the command will return the packages which name matches the search term.
Package Information ( apt show ) #
The information about the package dependencies, installation size, the package source, and so on might be useful before removing or installing a new package.
To retrieve information about a given package, use the show command:
Conclusion #
Knowing how to manage packages is an essential part of Linux system administration.
Feel free to leave a comment if you have any questions.
Using apt Commands in Linux [Complete Guide]
Brief: This article shows you how to use apt commands in Linux with examples so that you can manage packages effectively.
If you are using Debian, Ubuntu, Linux Mint or any other Debian or Ubuntu based distributions, you must have come across some apt commands by now.
First noticed in Ubuntu 16.04, apt is slowly gaining popularity. As more and more Ubuntu based Linux distributions are pushing for apt to be the recommended command for package management, it is time that you learn how to use apt commands.
In this guide for Linux beginners, I am going to explain you various apt commands with examples so that you can use them as an expert Linux user.
What is apt?
Debian Linux uses dpkg packaging system. A packaging system is a way to provide programs and applications for installation. This way, you don’t have to build a program from the source code which, trust me, is not a pretty way to handle packages. APT (Advanced Package Tool) is the command line tool to interact with the packaging system in Debian-based Linux distributions.
There is already dpkg commands to manage it. But APT is a more friendly way to handle packaging. You can use it to find and install new packages, upgrade packages, remove the packages etc.
apt commands provide command line way to interact with APT and manage packages.
At this point, I must mention apt-get is perhaps the most popular tool around APT. But apt is slowly promoted as its alternative. I have already explained the difference between apt and apt-get in a previous article along with why apt was introduced in the first place, therefore, I will not get into the details again.
Using apt commands to manage packages in Debian and Ubuntu based Linux distributions
I am using Ubuntu 16.04 in this tutorial but you can use any other Debian/Ubuntu based Linux distributions such as Linux Mint, elementary OS, Linux Lite etc.
Also, I am using Pop icon and theme in Ubuntu so my terminal looks different than the usual purple themed terminal.
If you prefer, you can watch this video of essential apt commands for Ubuntu users.
Update package database with apt
apt actually works on a database of available packages. If the database is not updated, the system won’t know if there are any newer packages available. This is why updating the repository should be the first thing to do in in any Linux system after a fresh install.
Updating the package database requires superuser privileges so you’ll need to use sudo.
When you run this command, you’ll see the package information being retrieved from various servers.
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-300×219.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples.png» width=»734″ height=»536″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples.png» alt=»apt command example with apt update» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-300×219.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> apt update will update the package database
You’ll see three types of lines here, Hit, Get and Ign. Basically these are:
Upgrade installed packages with apt
Once you have updated the package database, you can now upgrade the installed packages. The most convenient way is to upgrade all the packages that have available updates. You can simply use the command below:
This will show you how many and which all packages are going to be upgraded.
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-1-300×177.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-1.png» width=»734″ height=»434″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-1.png» alt=»Using apt commands in Ubuntu» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-1.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-1-300×177.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-1.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Upgrade all packages at once
There is another way to provide a complete upgrade by using the command below:
full-upgrade works the same as upgrade except that if system upgrade needs the removal of a package already installed on the system, it will do that. Whereas, the normal upgrade command won’t do this.
What is the difference between apt update and apt upgrade?
Though it sounds like when you do an apt update, it will update the packages and you’ll get the latest version of the package. But that’s not true. apt update only updates the database of the packages.
For example, if you have XYZ package version 1.3 installed, after apt update, the database will be aware that a newer version 1.4 is available. When you do an apt upgrade after apt update, it upgrades (or updates, whichever term you prefer) the installed packages to the newer version.
This is the reason why the fastest and the most convenient way to update Ubuntu system by using this command:
How to install new packages with apt
If you already know the name of the package, you can install it using the command below:
Just replace the
with the desired package. Suppose you want to install mplayer, you can simply use the command below:
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-3-300×177.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-3.png» width=»734″ height=»434″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-3.png» alt=»Install package using apt command in Linux» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-3.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-3-300×177.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-3.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Install package using apt
The good thing here is that you can use auto-completion. So, if you are not sure about the exact package name, you can type a few letters and press tab and it will suggest all the packages available with those letters. For example:
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-2-300×56.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-2.png» width=»734″ height=»136″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-2.png» alt=»Use apt command to install packages in Linux» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-2.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-2-300×56.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-2.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Use auto-completion to find packages with given name
How to install multiple packages with apt
You are not bound to install just one package at a time. You can install several packages at a time by providing the package names all together:
What if you run apt install on an already installed package?
No need to worry. This will just look into the database and if a newer version is found, it will upgrade the installed package to the newer one. So no harm is done by using it, unless you don’t want it to be upgraded.
How to install packages without upgrading
If for some reason you want to install a package, but don’t want to upgrade, it if it is already installed. In that case, you can use the option –no-upgrade in the following manner:
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-4-300×76.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-4.png» width=»734″ height=»185″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-4.png» alt=»use apt commands in Ubuntu» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-4.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-4-300×76.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-4.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Install without upgrading
How to only upgrade packages, not install it
If you only want to upgrade a package but don’t want to install it (if it’s not already installed), you can do that with the following command:
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-5-300×73.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-5.png» width=»734″ height=»178″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-5.png» alt=»Using apt commands with examples» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-5.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-5-300×73.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-5.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Only upgrade a package
How to install a specific version of an application
By default, the latest version available in the repository will be installed for an application. But if you don’t want to install the latest version, you can specify the version number. You would need to know the exact version number that you want to install.
Just add =version with the name of the package.
How to remove installed packages with apt
Enough talk about installing packages, let’s see how to remove packages. Removing packages is as easy as installing them. Just use the command below:
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-6-e1499720021872-300×145.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-6-e1499720021872.png» width=»733″ height=»355″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-6-e1499720021872.png» alt=»apt command examples» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-6-e1499720021872.png 733w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-6-e1499720021872-300×145.png 300w» data-lazy-sizes=»(max-width: 733px) 100vw, 733px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-6-e1499720021872.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Remove a package
Auto-completion works here as well. So you just start typing package name and press tab and it will suggest all the installed packages starting with those letters.
Another way of uninstalling packages is to use purge. The command is used in the following manner:
What is the difference between apt remove and apt purge?
If you used apt remove to a get rid of a particular software and then install it again, your software will have the same configuration files. Of course, you will be asked to override the existing configuration files when you install it again.
Purge is useful when you have messed up with the configuration of a program. You want to completely erase its traces from the system and perhaps start afresh. And yes, you can use apt purge on an already removed package.
Usually, apt remove is more than enough for uninstalling a package.
Search for packages
Not my preferred way of searching for packages. But this is useful when you are looking for some specific lib. Just use the following command with desired search terms. It will find all the packages containing your search term.
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-8-300×177.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-8.png» width=»734″ height=»434″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-8.png» alt=»Search for a package using apt command in Linux» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-8.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-8-300×177.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-8.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Search for a package
See the content of a package
If you want to know more about a package before installing or removing it, you can use the below command:
This will show information about the given package(s) like its dependencies, installation and download size, different sources the package is available from, the description of the content of the package among other things:
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-7-300×177.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-7.png» width=»734″ height=»434″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-7.png» alt=»Show the package information in apt» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-7.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-7-300×177.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-7.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Show the package information
List upgradable and installed versions
apt command has a new option called list. Using this command, you can see all the packages that have a newer version ready to be upgraded:
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-9-300×177.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-9.png» width=»734″ height=»434″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-9.png» alt=»List all upgradeable packages using apt command in Linux» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-9.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-9-300×177.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-9.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> List all upgradeable packages
You can also see all the installed packages on the system with installed option:
There is also a third option called –all-versions. It will list all the packages available for your system:
How to clean your system with apt
I have talked about ways of cleaning Ubuntu system to free up space. Unlike apt-get, you don’t have clean and autoclean commands here. You can still use the autoremove option and free up some diskspace:
This command removes libs and packages that were installed automatically to satisfy the dependencies of an installed package. If the package is removed, these automatically installed packages, though useless, remains in the system.
» data-medium-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-10-300×90.png» data-large-file=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-10.png» width=»734″ height=»220″ src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-10.png» alt=»Use aot command to free up space in Ubuntu Linux» data-lazy-srcset=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-10.png 734w, https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-10-300×90.png 300w» data-lazy-sizes=»(max-width: 734px) 100vw, 734px» data-lazy-src=»https://itsfoss.com/wp-content/uploads/2017/07/apt-commands-examples-10.png?is-pending-load=1″ srcset=»data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″> Use autoremove to free up space
I had recently cleaned my system and that is why it shows only a few Kb of files to be removed. Otherwise, you could easily get 100s of Mb of free space with this command.
Your input
I have deliberately not included apt edit-sources command in this article. It’s because this command option is a work in progress and at this point, it does nothing more than opening the sources.list file in the editor of your choice.
How do you like this guide for using apt commands in Linux? I hope it was easy to understand apt commands with examples. Your feedback will help in creating more such guides in the near future.
Creator of It’s FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries ranging from Agatha Christie and Sherlock Holmes to Detective Columbo & Ellery Queen. Also a movie buff with a soft corner for film noir.