When installing a package, apt
will ask to install other packages as well. This is because apt
automatically resolves any necessary package dependencies for us and installs the needed additional library and software packages. This is a wonderful feature included in many package management systems.
Upgrading Software with apt
While apt
helps protect you from problems installing software, trying to coordinate a multiple‐package update with dependencies can get tricky. To safely upgrade all the software packages on a system with any new versions in the repository, use the upgrade
command (again, using sudo
to obtain root privileges).
sudo apt upgrade
Notice that this command doesn't take any software package names as an argument. That's because the upgrade
option will upgrade all the installed packages to the most recent version available in the repository, which is safer for system stabilization.
Figure 3.1 shows a sample output from running the apt upgrade
command.
In the Figure 3.1 output, notice that apt
lists the packages that will be upgraded, but also any new packages that are required to be installed because of upgrades.
The upgrade
command won't remove any packages as part of the upgrade process. If a package needs to be removed as part of an upgrade, use the following command:
sudo apt full-upgrade
Although this may seem like an odd thing, sometimes it's required to remove packages to keep things synchronized between distribution upgrades.
FIGURE 3.1 Upgrading Ubuntu using apt
UPDATING A NEW INSTALLATION
Obviously, running apt
's upgrade
option is something you should do on a regular basis to keep your system up‐to‐date. However, it is especially important to run it after a fresh distribution installation. Usually there are lots of security patches and updates that are released since the last full release of a distribution.
Uninstalling Software with apt
Getting rid of software packages with apt
is as easy as installing and upgrading them. The only real choice you have to make is whether to keep the software's data and configuration files around afterward.
To remove a software package but not the data and configuration files, use apt
's remove
command. To remove a software package and the related data and configuration files, use the purge
option.
$ sudo apt purge zsh Reading package lists… Done Building dependency tree Reading state information… Done The following package was automatically installed and is no longer required: zsh-common Use 'sudo apt autoremove' to remove it. The following packages will be REMOVED: zsh* 0 upgraded, 0 newly installed, 1 to remove and 56 not upgraded. After this operation, 2,390 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database … 180985 files and directories currently installed.) Removing zsh (5.8-3ubuntu1) … Processing triggers for man-db (2.9.1-1) … (Reading database … 180928 files and directories currently installed.) Purging configuration files for zsh (5.8-3ubuntu1) … $
Notice, though, as part of the purge
output, apt
warns us that the zsh‐common
package that was installed as a dependency wasn't removed automatically, just in case it might be required for some other package. If you're sure the dependency package isn't required by anything else, you can remove it using the autoremove
command.
$ sudo apt autoremove Reading package lists… Done Building dependency tree Reading state information… Done The following packages will be REMOVED: zsh-common 0 upgraded, 0 newly installed, 1 to remove and 56 not upgraded. After this operation, 15.6 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database … 180928 files and directories currently installed.) Removing zsh-common (5.8-3ubuntu1) … Processing triggers for man-db (2.9.1-1) … $
The autoremove
command will check for all packages that are marked as dependencies and no longer required.
The apt Repositories
The default software repository locations for apt
are set up for you when you install your Linux distribution. The repository locations are stored in the file /etc/apt/sources.list
.
In most cases, you will never need to add or remove a software repository, so you won't need to touch this file. However, apt
will only pull software from these repositories. Also, when searching for software to install or update, apt
will only check these repositories. If you need to include some additional software repositories for your package management system, this is the place to do it.
SOFTWARE VERSIONS
The Linux distribution developers work hard to make sure package versions added to the repositories don't conflict with one another. Usually it's safest to upgrade or install a software package from the repository. Even if a newer version is available elsewhere, you may want to hold off installing it until that version is available in your Linux distribution's repository.
When you look at the file, you'll notice that it's full of helpful comments and warnings. The repository sources specified use the following structure:
deb (or deb-src) address distribution_name package_type_list
The deb
or deb‐src
value indicates the software package type. The deb
value indicates it is a source of compiled programs, whereas the deb‐src
value indicates it is a source of source code.
The address entry is the software repository's web address. The distribution_name entry is the name of this particular software repository's distribution's version. In the example, the distribution name is focal
. This does not necessarily mean that the distribution you are running is Ubuntu's Focal Fossa; it just means the Linux distribution is using the Ubuntu Focal Fossa software repositories. For example, in Linux Mint's sources.list
file, you will see a mix of Linux Mint and Ubuntu software repositories.
Finally, the package_type_list entry may be more than one word and indicates what type of packages the repository has in it. For example, you may see values such as main
, restricted
, universe
, or partner
.
When you need to add a software repository to your sources file, you can try to wing it yourself, but that more than likely will cause problems. Often, software repository sites or various package developer sites will have an exact line of text that you can copy from their website and paste into your sources.list
file. It's best to choose the safer route and just copy and paste.
The front‐end interface, apt
, provides intelligent command‐line options for working with the Debian‐based dpkg
utility.
Using Snap Containers
Canonical, the creators of the Ubuntu Linux distribution, has developed an application container format called snap.