Tìm hiểu lệnh yum trong linux

Giới thiệu về lệnh yum

Lệnh yum (Yellowdog Updater, Modified) trình quản lý gói dựa trên RPM, được sử dụng để cài đặt, cập nhật, gỡ bỏ hoặc tìm kiếm các gói phần mềm trong các bản phân phối Linux khác nhau bao gồm CentOS, RHEL và Fedora. yum sử dụng nhiều kho lưu trữ của bên thứ ba để cài đặt các gói tự động bằng cách giải quyết các vấn đề phụ thuộc của chúng.

Sử dụng lệnh yum

Cài đặt gói bằng yum install

Để cài đặt gói chúng ta sử dụng lệnh yum install packagename. Điều này sẽ xác định các phụ thuộc tự động và cài đặt chúng.

[root@docker-dev ~]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.vhost.vn
* epel: ftp.iij.ad.jp
* extras: mirrors.vhost.vn
* updates: mirrors.vhost.vn
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-93.el7.centos for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-93.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-93.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Installing:
httpd x86_64 2.4.6-93.el7.centos base 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-5.el7 base 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
httpd-tools x86_64 2.4.6-93.el7.centos base 92 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
=============================================================================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]:
Is this ok [y/d/N]: y
Downloading packages:
(1/5): httpd-tools-2.4.6-93.el7.centos.x86_64.rpm | 92 kB 00:00:00
(2/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(3/5): apr-1.4.8-5.el7.x86_64.rpm | 103 kB 00:00:00
(4/5): httpd-2.4.6-93.el7.centos.x86_64.rpm | 2.7 MB 00:00:01
(5/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:01
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.5 MB/s | 3.0 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-5.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-93.el7.centos.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-93.el7.centos.x86_64 5/5
Verifying : apr-1.4.8-5.el7.x86_64 1/5
Verifying : httpd-tools-2.4.6-93.el7.centos.x86_64 2/5
Verifying : mailcap-2.1.41-2.el7.noarch 3/5
Verifying : httpd-2.4.6-93.el7.centos.x86_64 4/5
Verifying : apr-util-1.5.2-6.el7.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-93.el7.centos
Dependency Installed:
apr.x86_64 0:1.4.8-5.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-93.el7.centos mailcap.noarch 0:2.1.41-2.el7
Complete!

Gỡ cài đặt gói bằng yum remove

Để xóa gói (cùng với tất cả các phụ thuộc của gói), sử dụng yum remove như bên dưới:

[root@docker-dev ~]# yum remove httpd
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Removing:
httpd x86_64 2.4.6-93.el7.centos @base 9.4 M
Transaction Summary
=============================================================================================================================================================
Remove 1 Package
Installed size: 9.4 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : httpd-2.4.6-93.el7.centos.x86_64 1/1
Verifying : httpd-2.4.6-93.el7.centos.x86_64 1/1
Removed:
httpd.x86_64 0:2.4.6-93.el7.centos
Complete!

Liệt kê gói bằng yum list

Sử dụng yum list để tìm kiếm gói cụ thể có tên.

[root@docker-dev ~]# yum list httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.vhost.vn
* epel: ftp.iij.ad.jp
* extras: mirrors.vhost.vn
* updates: mirrors.vhost.vn
Installed Packages
httpd.x86_64

Tìm kiếm gói bằng yum seach

Nếu bạn không biết chính xác tên gói cần cài đặt, hãy sử dụng yum seach, sẽ giúp chúng ta tìm kiếm tất cả các gói khớp với từ khóa chúng ta cần tìm và hiển thị nó.

[root@docker-dev ~]# yum search nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.vhost.vn
* epel: ftp.iij.ad.jp
* extras: mirrors.vhost.vn
* updates: mirrors.vhost.vn
==================================================================== N/S matched: nginx =====================================================================
collectd-nginx.x86_64 : Nginx plugin for collectd
munin-nginx.noarch : NGINX support for Munin resource monitoring
nextcloud-nginx.noarch : Nginx integration for NextCloud
nginx-all-modules.noarch : A meta package that installs all available Nginx modules
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
nginx-mod-mail.x86_64 : Nginx mail modules
nginx-mod-stream.x86_64 : Nginx stream modules
owncloud-nginx.noarch : Nginx integration for ownCloud
pagure-web-nginx.noarch : Nginx configuration for Pagure
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
python2-certbot-nginx.noarch : The nginx plugin for certbot
sympa-nginx.x86_64 : Sympa with nginx
nginx.x86_64 : A high performance web server and reverse proxy server
Name and summary matches only, use "search all" for everything.

Nhận thông tin về gói yum

Nếu chúng ta muốn biết thông tin của gói trước khi cài đặt. Để có được thông tin của một gói chỉ cần chạy lệnh sau:

# yum info nginx

Liệt kê tất cả các gói có sẵn bằng yum

Lệnh sau sẽ liệt kê tất cả các gói có sẵn trong cơ sở dữ liệu yum:

# yum list | less

Liệt kê tất cả các gói đã cài đặt bằng yum

Để xem tất cả các gói được cài đặt trên hệ thống của bạn, thực hiện như sau:

# yum list installed | less

Kiểm tra cập nhật có sẵn bằng yum

Để kiểm tra xem có bao nhiêu gói đã cài đặt trên hệ thống của bạn có sẵn các bản cập nhật, chúng ta chạy lệnh sau:

# yum check-update

Cập nhật hệ thống bằng yum

Để cập nhật hệ thống của bạn tất cả các gói có bản cập nhật mới chúng ta chạy lệnh sau. Nó sẽ cài đặt tất cả các bản vá mới nhất và cập nhật bảo mật cho hệ thống của bạn.

# yum update

Liệt kê tất cả các kho yum được kích hoạt và vô hiệu hóa

# yum repolist all

Cài đặt gói từ Kho lưu trữ cụ thể

Theo mặc định, lệnh yum chỉ cài đặt từ kho được kích hoạt. Vì một số lý do bạn muốn cài đặt một gói từ kho lưu trữ bị vô hiệu hóa, bạn có thể sử dụng tùy chọn enenablerepo trong yum install như sau

# yum --enablerepo=base install httpd

Clean bộ nhớ cache bằng yum

Để xóa tất cả các tệp được lưu trong bộ nhớ cache được kích hoạt, bạn cần chạy lệnh sau để dọn sạch tất cả bộ đệm. Chúng ta thực hiện như bên dưới:

# yum clean all

Xem Lịch sử của Yum

Để xem tất cả các lệnh yum trong quá khứ, chúng ta chạy lệnh sau.

# yum history list

Còn tiếp…

Bài viết liên quan

Leave a Reply

Your email address will not be published. Required fields are marked *