Giới thiệu
Trong lab này, chúng ta sẽ khám phá trình quản lý gói aptitude trên một container Docker Ubuntu 22.04. Chúng ta sẽ học cách cài đặt và cập nhật aptitude, thực hiện tìm kiếm gói và tra cứu thông tin, đồng thời quản lý việc cài đặt, nâng cấp và gỡ bỏ gói bằng các lệnh aptitude. Lab này bao gồm các tác vụ quản lý gói thiết yếu, cung cấp các ví dụ thực tế để nâng cao kỹ năng quản trị hệ thống Linux của bạn.
Cài đặt và cập nhật Trình quản lý gói aptitude
Trong bước này, chúng ta sẽ cài đặt và cập nhật trình quản lý gói aptitude trên container Docker Ubuntu 22.04 của chúng ta.
Đầu tiên, hãy cập nhật chỉ mục gói để đảm bảo chúng ta có thông tin gói mới nhất:
sudo apt-get update
Ví dụ đầu ra:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 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
Tiếp theo, hãy cài đặt trình quản lý gói aptitude:
sudo apt update
sudo apt-get install -y aptitude
Ví dụ đầu ra:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
aptitude-common libboost-iostreams1.74.0 libboost-system1.74.0 libcwidget3v5 libept1.5.0 libxapian30
Suggested packages:
aptitude-doc-en aptitude-doc
The following NEW packages will be installed:
aptitude aptitude-common libboost-iostreams1.74.0 libboost-system1.74.0 libcwidget3v5 libept1.5.0 libxapian30
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,450 kB of archives.
After this operation, 5,580 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 libboost-iostreams1.74.0 amd64 1.74.0-8ubuntu3 [139 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libboost-system1.74.0 amd64 1.74.0-8ubuntu3 [94.7 kB]
...
Fetched 1,450 kB in 1s (1,450 kB/s)
Selecting previously unselected package aptitude-common.
(Reading database ... 18284 files and directories currently installed.)
Preparing to unpack .../aptitude-common_0.8.12-1ubuntu1_all.deb ...
Unpacking aptitude-common (0.8.12-1ubuntu1) ...
Selecting previously unselected package aptitude.
Preparing to unpack .../aptitude_0.8.12-1ubuntu1_amd64.deb ...
Unpacking aptitude (0.8.12-1ubuntu1) ...
Setting up libboost-iostreams1.74.0:amd64 (1.74.0-8ubuntu3) ...
Setting up libboost-system1.74.0:amd64 (1.74.0-8ubuntu3) ...
Setting up libcwidget3v5:amd64 (0.5.17-7build1) ...
Setting up libept1.5.0:amd64 (1.1+nmu3ubuntu2) ...
Setting up libxapian30:amd64 (1.4.18-3ubuntu1) ...
Setting up aptitude-common (0.8.12-1ubuntu1) ...
Setting up aptitude (0.8.12-1ubuntu1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...
Bây giờ, hãy xác minh rằng aptitude đã được cài đặt và cập nhật:
Thực hiện tìm kiếm gói và tra cứu thông tin với aptitude
Trong bước này, chúng ta sẽ học cách sử dụng trình quản lý gói aptitude để tìm kiếm gói và truy xuất thông tin về chúng.
Đầu tiên, hãy tìm kiếm một gói bằng lệnh aptitude search
. Ví dụ: hãy tìm kiếm gói "nginx":
sudo aptitude search nginx
Ví dụ đầu ra:
i nginx - high performance web server
p nginx-core - nginx web server (core version)
p nginx-doc - documentation for nginx
p nginx-extras - nginx web server (extended version)
p nginx-full - nginx web server (standard version)
p nginx-light - nginx web server (basic version)
Đầu ra cho thấy có một số gói liên quan đến nginx. Tiền tố "i" cho biết gói "nginx" hiện đã được cài đặt.
Tiếp theo, hãy lấy thông tin chi tiết về gói "nginx" bằng lệnh aptitude show
:
sudo aptitude show nginx
Ví dụ đầu ra:
Package: nginx
State: installed
Automatically installed: no
Version: 1.18.0-0ubuntu1.2
Priority: optional
Section: web
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Uncompressed Size: 1,518 k
Depends: nginx-core (= 1.18.0-0ubuntu1.2), lsb-base (>= 3.0-10)
Suggests: nginx-doc, www-browser
Description: high performance web server
Nginx is a high performance web server and reverse proxy server. It is
known for its high performance, stability, rich feature set, simple
configuration, and low resource consumption.
Điều này cung cấp thông tin chi tiết về gói "nginx", bao gồm phiên bản, các phụ thuộc và mô tả về gói.
Cài đặt, nâng cấp và gỡ bỏ gói bằng aptitude
Trong bước này, chúng ta sẽ học cách sử dụng aptitude để cài đặt, nâng cấp và gỡ bỏ gói.
Đầu tiên, hãy cài đặt một gói mới bằng lệnh aptitude install
. Chúng ta sẽ cài đặt gói "tree", một tiện ích dòng lệnh hiển thị cấu trúc thư mục ở định dạng giống như cây:
sudo aptitude install tree
Ví dụ đầu ra:
The following NEW packages will be installed:
tree
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 44.2 kB of archives. After this operation, 123 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 tree amd64 1.8.0-1build1 [44.2 kB]
Fetched 44.2 kB in 0s (89.3 kB/s)
Selecting previously unselected package tree.
(Reading database ... 18291 files and directories currently installed.)
Preparing to unpack .../tree_1.8.0-1build1_amd64.deb ...
Unpacking tree (1.8.0-1build1) ...
Setting up tree (1.8.0-1build1) ...
Processing triggers for man-db (2.10.2-1) ...
Tiếp theo, hãy nâng cấp một gói bằng lệnh aptitude safe-upgrade
. Chúng ta sẽ nâng cấp gói "vim" lên phiên bản mới nhất:
sudo aptitude safe-upgrade vim
Ví dụ đầu ra:
The following packages will be upgraded:
vim vim-common vim-runtime
3 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 6,483 kB of archives. After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n/?] y
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim-common amd64 2:8.2.3995-1ubuntu2.1 [2,138 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim-runtime all 2:8.2.3995-1ubuntu2.1 [4,178 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 vim amd64 2:8.2.3995-1ubuntu2.1 [167 kB]
Fetched 6,483 kB in 1s (6,483 kB/s)
(Reading database ... 18292 files and directories currently installed.)
Preparing to unpack .../vim-common_2%3a8.2.3995-1ubuntu2.1_amd64.deb ...
Unpacking vim-common (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Preparing to unpack .../vim-runtime_2%3a8.2.3995-1ubuntu2.1_all.deb ...
Unpacking vim-runtime (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Preparing to unpack .../vim_2%3a8.2.3995-1ubuntu2.1_amd64.deb ...
Unpacking vim (2:8.2.3995-1ubuntu2.1) over (2:8.2.3995-1ubuntu2) ...
Setting up vim-common (2:8.2.3995-1ubuntu2.1) ...
Setting up vim-runtime (2:8.2.3995-1ubuntu2.1) ...
Setting up vim (2:8.2.3995-1ubuntu2.1) ...
Processing triggers for man-db (2.10.2-1) ...
Cuối cùng, hãy gỡ bỏ gói "tree" bằng lệnh aptitude remove
:
sudo aptitude remove tree
Ví dụ đầu ra:
The following packages will be REMOVED:
tree
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0 B of archives. After this operation, 123 kB disk space will be freed.
Do you want to continue? [Y/n/?] y
(Reading database ... 18292 files and directories currently installed.)
Removing tree (1.8.0-1build1) ...
Processing triggers for man-db (2.10.2-1) ...
Tóm tắt
Trong lab này, chúng ta đã học cách cài đặt và cập nhật trình quản lý gói aptitude trên container Docker Ubuntu 22.04 của chúng ta. Chúng ta bắt đầu bằng cách cập nhật chỉ mục gói để đảm bảo chúng ta có thông tin gói mới nhất, sau đó cài đặt trình quản lý gói aptitude. Chúng ta cũng đã khám phá cách thực hiện tìm kiếm gói và tra cứu thông tin, cũng như cách cài đặt, nâng cấp và gỡ bỏ gói bằng aptitude.