介绍
在本实验中,你将学习如何使用各种包管理命令(包括 apt-get
、apt
和 snap
)来安装 Linux 软件包。实验涵盖了更新包列表、安装新软件包以及理解这些命令输出的基本步骤。此外,实验还介绍了替代的包管理工具及其适用场景,帮助你全面理解 Linux 系统上的软件包安装。
在本实验中,你将学习如何使用各种包管理命令(包括 apt-get
、apt
和 snap
)来安装 Linux 软件包。实验涵盖了更新包列表、安装新软件包以及理解这些命令输出的基本步骤。此外,实验还介绍了替代的包管理工具及其适用场景,帮助你全面理解 Linux 系统上的软件包安装。
在这一步中,你将学习如何使用 apt-get
命令安装 Linux 软件包。apt-get
是一个强大的工具,用于管理基于 Ubuntu 的 Linux 发行版上的软件包。
首先,让我们更新软件包列表,以确保我们拥有关于可用软件包的最新信息:
sudo apt-get update
示例输出:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done
接下来,我们使用 apt-get install
安装一个软件包。我们将安装 tree
软件包,这是一个命令行工具,用于以树状格式显示目录结构:
sudo apt update
sudo apt-get install -y tree
示例输出:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libglib2.0-0 libicu70 libncurses6 libpcre2-8-0 libreadline8 libstdc++6 libtinfo6 zlib1g
Suggested packages:
rsync
The following NEW packages will be installed:
libglib2.0-0 libicu70 libncurses6 libpcre2-8-0 libreadline8 libstdc++6 libtinfo6 tree zlib1g
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,010 kB of archives.
After this operation, 11.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libglib2.0-0 amd64 2.72.1-1ubuntu1 [1,264 kB]
...
Fetched 3,010 kB in 1s (3,010 kB/s)
Selecting previously unselected package libglib2.0-0:amd64.
(Reading database ... 17869 files and directories currently installed.)
Preparing to unpack .../libglib2.0-0_2.72.1-1ubuntu1_amd64.deb ...
Unpacking libglib2.0-0:amd64 (2.72.1-1ubuntu1) ...
...
Setting up tree (1.8.0-1ubuntu1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...
apt-get install
命令会下载软件包及其依赖项,然后将它们安装到你的系统中。
你也可以使用 apt-get remove
命令移除软件包:
sudo apt-get remove -y tree
示例输出:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
tree
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 116 kB of disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 17874 files and directories currently installed.)
Removing tree (1.8.0-1ubuntu1) ...
Processing triggers for man-db (2.10.2-1) ...
apt-get remove
命令会从你的系统中移除指定的软件包。
在这一步中,你将学习如何使用 apt
命令安装 Linux 软件包。apt
命令是 apt-get
命令的用户友好界面,提供了一种更简单、更直观的方式来管理软件包。
首先,让我们再次更新软件包列表:
sudo apt update
示例输出:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done
接下来,我们安装 htop
软件包,这是一个流行的系统监控工具:
sudo apt install -y htop
示例输出:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libncursesw6 libsensors-config libsensors5 libstdc++6
Suggested packages:
lm-sensors
The following NEW packages will be installed:
htop libncursesw6 libsensors-config libsensors5 libstdc++6
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 390 kB of archives.
After this operation, 1,493 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libncursesw6 amd64 6.3-2 [115 kB]
...
Fetched 390 kB in 1s (390 kB/s)
Selecting previously unselected package libncursesw6:amd64.
(Reading database ... 17874 files and directories currently installed.)
Preparing to unpack .../libncursesw6_6.3-2_amd64.deb ...
Unpacking libncursesw6:amd64 (6.3-2) ...
...
Setting up htop (3.0.5-1) ...
Processing triggers for man-db (2.10.2-1) ...
apt install
命令会下载软件包及其依赖项,然后将它们安装到你的系统中。
你也可以使用 apt remove
命令移除软件包:
sudo apt remove -y htop
示例输出:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
htop
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,493 kB of disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 17879 files and directories currently installed.)
Removing htop (3.0.5-1) ...
Processing triggers for man-db (2.10.2-1) ...
apt remove
命令会从你的系统中移除指定的软件包。
在这一步中,你将学习如何使用 Snap 包管理器安装 Linux 软件包。Snap 是由 Canonical 为 Ubuntu 和其他 Linux 发行版开发的容器化软件打包和部署系统。
首先,让我们确保 Snap 服务正在运行:
sudo systemctl status snapd
示例输出:
● snapd.service - Snap Daemon
Loaded: loaded (/lib/systemd/system/snapd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-04-21 07:15:09 UTC; 1min 30s ago
Docs: https://snapcraft.io
Main PID: 1216 (snapd)
Tasks: 10 (limit: 4915)
Memory: 33.2M
CPU: 375ms
CGroup: /system.slice/snapd.service
└─1216 /usr/lib/snapd/snapd
Apr 21 07:15:09 lab-ubuntu-22.04 systemd[1]: Started Snap Daemon.
接下来,我们使用 Snap 命令安装 vlc
软件包:
sudo snap install vlc
示例输出:
vlc 3.0.18 from 'videolan' installed
snap install
命令会下载并安装指定的 Snap 软件包到你的系统中。
你也可以使用 snap remove
命令移除软件包:
sudo snap remove vlc
示例输出:
vlc removed
snap remove
命令会从你的系统中移除指定的 Snap 软件包。
在本实验中,你学习了如何使用 apt-get
命令安装 Linux 软件包,这是一个强大的工具,用于管理基于 Ubuntu 的 Linux 发行版上的软件包。你首先更新了软件包列表,以确保拥有关于可用软件包的最新信息。接着,你安装了 tree
软件包,这是一个命令行工具,用于以树状格式显示目录结构。
你还学习了如何使用 apt
命令安装 Linux 软件包,这是一个比 apt-get
更新且更用户友好的包管理工具。此外,你还探索了 Snap 包管理器的使用,它提供了一种不同的方式来在 Linux 系统上安装和管理软件。