Mastering Linux System Administration. Richard Blum
Чтение книги онлайн.
Читать онлайн книгу Mastering Linux System Administration - Richard Blum страница 25
Once you find the package you'd like to install, installing it using apt
is as easy as this:
sudo apt install <?i Start?>package_name<?i End?>
Since installing new software requires root privileges, you must use the sudo
command in Ubuntu. The output will show basic information about the package and ask if you want to proceed with the installation.
INSTALLING SOFTWARE USING APT
Using the apt
command makes installing software in Ubuntu easy. In this exercise, you'll install the Z shell on your Ubuntu server.
1 Log into your Linux system as the sysadmin account created in Chapter 2, “Installing an Ubuntu Server.”
2 From the command prompt, enter the command sudo apt install zsh. The sudo command is required to allow your user to run the apt command with root user privileges. Enter your user password when prompted. You should see something similar to this output: [sudo] password for sysadmin: Reading package lists… Done Building dependency tree Reading state information… Done The following additional packages will be installed: zsh-common Suggested packages: zsh-doc The following NEW packages will be installed: zsh zsh-common 0 upgraded, 2 newly installed, 0 to remove and 56 not upgraded. Need to get 4,450 kB of archives. After this operation, 18.0 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://us.archive.ubuntu.com/ubuntu focal/main amd64 zsh-common all 5.8-3ubuntu1 [3,744 kB] Get:2 http://us.archive.ubuntu.com/ubuntu focal/main amd64 zsh amd64 5.8-3ubuntu1 [707 kB] Fetched 4,450 kB in 4s (1,039 kB/s) Selecting previously unselected package zsh-common. (Reading database … 179515 files and directories currently installed.) Preparing to unpack …/zsh-common_5.8-3ubuntu1_all.deb … Unpacking zsh-common (5.8-3ubuntu1) … Selecting previously unselected package zsh. Preparing to unpack …/zsh_5.8-3ubuntu1_amd64.deb … Unpacking zsh (5.8-3ubuntu1) … Setting up zsh-common (5.8-3ubuntu1) … Setting up zsh (5.8-3ubuntu1) … Processing triggers for man-db (2.9.1-1) … $
3 Test the install by entering the command zsh. You will see a menu prompting if you want to customize your Z shell environment. Enter 0 to use the default configuration. You should then get the Z shell prompt. ubuntu-server%
4 Return to your normal Bash Shell by typing the command exit.
5 Check whether the installation processed properly, type the command apt ‐‐installed list. You should see the package appear, indicating that it is installed.
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