Bog'liq Mastering Ubuntu Server Gain expertise in the art of deploying, configuring, managing, and troubleshooting Ubuntu Server by Jay LaCroix (z-lib.org)
[ 86 ] Another neat default in Ubuntu Server is that it automatically configures most
packages to have their daemons start up and also be enabled so that they start with
each boot. Using the earlier example of
apache2
, the
apache2
service will start and
the application will automatically start running as soon as you install the package.
This may seem like a good idea for the sake of convenience, but not everyone prefers
this automation. As I've mentioned, the more packages installed on your server, the
higher the attack surface, but running services (also known as daemons, or units)
are each a method of entry for miscreants should there be a security vulnerability.
Therefore, some distributions don't enable and start daemons automatically when
you install packages. The way I see it, though, you should only install packages you
actually intend to use, so it stands to reason that if you go to the trouble of manually
installing a package such as Apache, you probably want to start using it.
When you install a package with the
apt
keyword, it searches its local database for
the package you named. If it doesn't find it, it will throw an error. Sometimes, this
error may be because the package isn't available or perhaps the version that
apt
wants to install no longer exists. Ubuntu's repositories move very fast; new versions
of packages are added almost daily. When a new version of a package is added,
its older equivalent may be removed. For this reason, it's recommended that you
update your package sources from time to time. Doing so is easy, using the following
command:
sudo apt update
This command doesn't actually update any packages; it merely checks in with your
local mirror to see if any packages have been added or removed and updates your
local index. This command is useful because installations of packages can fail if your
sources aren't up to date. In most cases, the symptom will be that
apt
errors out of
the process when it can't find a package it's looking for.
Removing packages is also very easy and follows a very similar syntax; you would
only need to replace the
install
keyword with
remove
:
sudo apt remove
And, just like with the
install
option, you can remove multiple packages at the
same time. The following example will remove three packages:
sudo apt remove
If you'd like to not only remove a package but also wipe out its configuration, you
can use the
--purge
option:
sudo apt remove --purge