パッケージ管理のための20のLinux YUM(Yellowdog Updater, Modified)コマンド

この記事では、RedHatが開発したYellowdog Updater Modifiedツールを使用して、Linuxシステムでパッケージのインストール、更新、削除、検索、パッケージおよびリポジトリの管理方法について学びます。

この記事で示されている例のコマンドは、実際にRHEL 8サーバーでテストされており、これらの資料を学習目的、RHEL認定、または新しいパッケージをインストールしシステムを最新の状態に保つ方法を探るために使用できます。

この記事の基本的な要件は、コマンドの基本的な理解と動作するLinuxオペレーティングシステムを持っていることです。以下にリストされているすべてのコマンドを探索して練習できます。

YUMYellowdog Updater Modified)は、RPMRedHat Package Manager)ベースのLinuxシステム向けのオープンソースのコマンドラインおよびグラフィカルベースのパッケージ管理ツールです。

システム上のソフトウェアパッケージを簡単にインストール、更新、削除、または検索できるようにユーザーおよびシステム管理者に可能にします。これは、GPL一般公衆利用許諾)の下で開発およびリリースされ、オープンソースとして

、誰でもバグを修正し、カスタマイズされたパッケージを開発するためのコードにアクセスできることを意味します。YUMは、依存関係の問題を解決してパッケージを自動的にインストールするために、多数のサードパーティーのリポジトリを使用します。

更新yumコマンドは、dnfコマンドに置き換えられました。これはYUMの次世代バージョンであり、新しいRPMベースのディストリビューションではYUMの代わりとされています。

1. YUMを使用してパッケージをインストールする

「Firefox」というパッケージをインストールするには、以下のコマンドを実行するだけで、Firefoxのすべての必要な依存関係を自動的に見つけてインストールします。

# yum install firefox
Loaded plugins: fastestmirror
Dependencies Resolved

================================================================================================
 Package                    Arch        Version                    Repository            Size        
================================================================================================
Updating:
firefox                        i686        10.0.6-1.el6.centos     updates             20 M
Updating for dependencies:
 xulrunner                     i686        10.0.6-1.el6.centos     updates             12 M

Transaction Summary
================================================================================================
Install       0 Package(s)
Upgrade       2 Package(s)

Total download size: 32 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): firefox-10.0.6-1.el6.centos.i686.rpm                                |  20 MB   01:10
(2/2): xulrunner-10.0.6-1.el6.centos.i686.rpm                              |  12 MB   00:52
------------------------------------------------------------------------------------------------
Total                                                           63 kB/s |  32 MB   02:04

Updated:
  firefox.i686 0:10.0.6-1.el6.centos

Dependency Updated:
  xulrunner.i686 0:10.0.6-1.el6.centos

Complete!

上記のコマンドは、システムにパッケージをインストールする前に確認を求めます。確認を求めずに自動的にパッケージをインストールしたい場合は、以下の例に示すようにオプション-yを使用します。2. YUMを使用してパッケージを削除する

# yum -y install firefox

2. YUMでパッケージを削除する

すべての依存関係とともにパッケージを完全に削除するには、以下に示すように次のコマンドを実行してください。

# yum remove firefox
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package firefox.i686 0:10.0.6-1.el6.centos set to be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package                    Arch        Version                        Repository            Size        
====================================================================================================
Removing:
 firefox                    i686        10.0.6-1.el6.centos            @updates              23 M

Transaction Summary
====================================================================================================
Remove        1 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)

Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing        : firefox-10.0.6-1.el6.centos.i686                                                                                                                          1/1

Removed:
  firefox.i686 0:10.0.6-1.el6.centos

Complete!

同様に、上記のコマンドはパッケージを削除する前に確認を求めるため、確認プロンプトを無効にするには、オプション-yを次のように追加してください。

# yum -y remove firefox

3. YUMを使用してパッケージを更新する

たとえば、MySQLパッケージの古いバージョンがあり、最新の安定版に更新したいとします。次のコマンドを実行するだけで、すべての依存関係の問題が自動的に解決され、インストールされます。

# yum update mysql
Loaded plugins: fastestmirror
Dependencies Resolved

============================================================================================================
 Package            Arch                Version                    Repository                    Size
============================================================================================================
Updating:
 vsftpd             i386                2.0.5-24.el5_8.1           updates                       144 k

Transaction Summary
============================================================================================================
Install       0 Package(s)
Upgrade       1 Package(s)

Total size: 144 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : vsftpd                                                                     1/2
  Cleanup        : vsftpd                                                                     2/2

Updated:
  vsftpd.i386 0:2.0.5-24.el5_8.1

Complete!

4. YUMを使用してパッケージをリストアップする

list機能を使用して、名前で特定のパッケージを検索します。たとえば、OpenSSHという名前のパッケージを検索するには、次のコマンドを使用します。

# yum list openssh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.neu.edu.cn
 * epel: mirror.neu.edu.cn
 * extras: mirror.neu.edu.cn
 * rpmforge: mirror.nl.leaseweb.net
 * updates: mirror.nus.edu.sg
Installed Packages
openssh.i386                                       4.3p2-72.el5_6.3                                                                      installed
Available Packages                                 4.3p2-82.el5                                                                          base

より正確な検索を行うために、バージョンがわかっている場合は、パッケージ名をバージョンで定義してください。たとえば、特定のバージョンOpenSSH-4.3p2のパッケージを検索するには、次のコマンドを使用します。

# yum list openssh-4.3p2

[ あなたが好むかもしれません: OpenSSHサーバーをセキュリティ保護およびハードンする方法 ]

5. YUMを使用してパッケージを検索する

パッケージの正確な名前を覚えていない場合は、検索機能を使用して指定されたパッケージ名に一致するすべての利用可能なパッケージを検索します。たとえば、単語に一致するすべてのパッケージを検索するには、.

# yum search vsftpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.neu.edu.cn
 * epel: mirror.neu.edu.cn
 * extras: mirror.neu.edu.cn
 * rpmforge: mirror.nl.leaseweb.net
 * updates: ftp.iitm.ac.in
============================== Matched: vsftpd ========================
ccze.i386 : A robust log colorizer
pure-ftpd-selinux.i386 : SELinux support for Pure-FTPD
vsftpd.i386 : vsftpd - Very Secure Ftp Daemon

6。YUMを使用してパッケージに関する情報を取得します

インストールする前にパッケージに関する情報を知りたいとします。パッケージに関する情報を取得するには、次のコマンドを発行してください。

# yum info firefox
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.neu.edu.cn
 * epel: mirror.neu.edu.cn
 * extras: mirror.neu.edu.cn
 * rpmforge: mirror.nl.leaseweb.net
 * updates: ftp.iitm.ac.in
Available Packages
Name       : firefox
Arch       : i386
Version    : 10.0.6
Release    : 1.el5.centos
Size       : 20 M
Repo       : updates
Summary    : Mozilla Firefox Web browser
URL        : http://www.mozilla.org/projects/firefox/
License    : MPLv1.1 or GPLv2+ or LGPLv2+
Description: Mozilla Firefox is an open-source web browser, designed for standards
           : compliance, performance and portability.

7。YUMを使用して利用可能なすべてのパッケージをリストします

Yumデータベース内のすべての利用可能なパッケージをリストするには、次のコマンドを使用します。

# yum list | less

8。YUMを使用してインストールされたすべてのパッケージをリストします

システム上のすべてのインストールされたパッケージをリストするには、次のコマンドを発行するだけで、すべてのインストールされたパッケージを表示します。

# yum list installed | less

9。Yum提供機能

Yum提供機能は、特定のファイルがどのパッケージに属しているかを見つけるために使用されます。たとえば、/etc/httpd/conf/httpd.confを持つパッケージの名前を知りたい場合。

# yum provides /etc/httpd/conf/httpd.conf
Loaded plugins: fastestmirror
httpd-2.2.3-63.el5.centos.i386 : Apache HTTP Server
Repo        : base
Matched from:
Filename    : /etc/httpd/conf/httpd.conf

httpd-2.2.3-63.el5.centos.1.i386 : Apache HTTP Server
Repo        : updates
Matched from:
Filename    : /etc/httpd/conf/httpd.conf

httpd-2.2.3-65.el5.centos.i386 : Apache HTTP Server
Repo        : updates
Matched from:
Filename    : /etc/httpd/conf/httpd.conf

httpd-2.2.3-53.el5.centos.1.i386 : Apache HTTP Server
Repo        : installed
Matched from:
Other       : Provides-match: /etc/httpd/conf/httpd.conf

10。Yumを使用して利用可能な更新を確認します

システム上のインストールされたパッケージの数に利用可能な更新があるかどうかを確認するには、次のコマンドを使用してください。

# yum check-update

11。YUMを使用してシステムを更新します

セキュリティとバイナリパッケージの更新と共にシステムを最新の状態に保つには、次のコマンドを実行してください。システムに最新のパッチとセキュリティ更新プログラムをインストールします。

# yum update

12。すべての利用可能なグループパッケージをリストします

Linuxでは、複数のパッケージが特定のグループにまとめられています。yumを使って個々のパッケージをインストールする代わりに、関連するすべてのパッケージが含まれる特定のグループをインストールできます。たとえば、利用可能なすべてのグループをリストするには、次のコマンドを発行します。

# yum grouplist
Installed Groups:
   Administration Tools
   DNS Name Server
   Dialup Networking Support
   Editors
   Engineering and Scientific
   FTP Server
   Graphics
   Java Development
   Legacy Network Server
Available Groups:
   Authoring and Publishing
   Base
   Beagle
   Cluster Storage
   Clustering
   Development Libraries
   Development Tools
   Eclipse
   Educational Software
   KDE (K Desktop Environment)
   KDE Software Development

13. グループパッケージのインストール

特定のパッケージグループをインストールするには、groupinstallオプションを使用します。たとえば、「MySQLデータベース」をインストールするには、次のコマンドを実行します。

# yum groupinstall 'MySQL Database'
Dependencies Resolved

=================================================================================================
Package								Arch      Version			 Repository        Size
=================================================================================================
Updating:
 unixODBC                           i386      2.2.11-10.el5      base              290 k
Installing for dependencies:
 unixODBC-libs                      i386      2.2.11-10.el5      base              551 k

Transaction Summary
=================================================================================================
Install       1 Package(s)
Upgrade       1 Package(s)

Total size: 841 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : unixODBC-libs	1/3
  Updating       : unixODBC         2/3
  Cleanup        : unixODBC         3/3

Dependency Installed:
  unixODBC-libs.i386 0:2.2.11-10.el5

Updated:
  unixODBC.i386 0:2.2.11-10.el5

Complete!

14. グループパッケージの更新

インストールされているグループパッケージを更新するには、次のように実行します。

# yum groupupdate 'DNS Name Server'

Dependencies Resolved
================================================================================================================
 Package			Arch	        Version				Repository           Size
================================================================================================================
Updating:
 bind                           i386            30:9.3.6-20.P1.el5_8.2          updates              981 k
 bind-chroot                    i386            30:9.3.6-20.P1.el5_8.2          updates              47 k
Updating for dependencies:
 bind-libs                      i386            30:9.3.6-20.P1.el5_8.2          updates              864 k
 bind-utils                     i386            30:9.3.6-20.P1.el5_8.2          updates              174 k

Transaction Summary
================================================================================================================
Install       0 Package(s)
Upgrade       4 Package(s)

Total size: 2.0 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : bind-libs            1/8
  Updating       : bind                 2/8
  Updating       : bind-chroot          3/8
  Updating       : bind-utils           4/8
  Cleanup        : bind                 5/8
  Cleanup        : bind-chroot          6/8
  Cleanup        : bind-utils           7/8
  Cleanup        : bind-libs            8/8

Updated:
  bind.i386 30:9.3.6-20.P1.el5_8.2                  bind-chroot.i386 30:9.3.6-20.P1.el5_8.2

Dependency Updated:
  bind-libs.i386 30:9.3.6-20.P1.el5_8.2             bind-utils.i386 30:9.3.6-20.P1.el5_8.2

Complete!

15. グループパッケージの削除

インストールされているグループをシステムから削除するには、次のコマンドを使用します。

# yum groupremove 'DNS Name Server'

Dependencies Resolved

===========================================================================================================
 Package                Arch              Version                         Repository          Size
===========================================================================================================
Removing:
 bind                   i386              30:9.3.6-20.P1.el5_8.2          installed           2.1 M
 bind-chroot            i386              30:9.3.6-20.P1.el5_8.2          installed           0.0

Transaction Summary
===========================================================================================================
Remove        2 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)

Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing        : bind                                                   1/2
warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave
  Erasing        : bind-chroot                                            2/2

Removed:
  bind.i386 30:9.3.6-20.P1.el5_8.2                                        bind-chroot.i386 30:9.3.6-20.P1.el5_8.2

Complete!

16. 有効なYumリポジトリのリスト

システム内のすべての有効なYumリポジトリをリストするには、次のオプションを使用します。

# yum repolist

repo id                     repo name                                            status
base                        CentOS-5 - Base                                      enabled:  2,725
epel                        Extra Packages for Enterprise Linux 5 - i386         enabled:  5,783
extras                      CentOS-5 - Extras                                    enabled:    282
mod-pagespeed               mod-pagespeed                                        enabled:      1
rpmforge                    RHEL 5 - RPMforge.net - dag                          enabled: 11,290
updates                     CentOS-5 - Updates                                   enabled:    743
repolist: 20,824

16. すべての有効/無効なYumリポジトリのリスト

次のコマンドを実行すると、システム上のすべての有効および無効なyumリポジトリが表示されます。

# yum repolist all

repo id                     repo name                                            status
C5.0-base                   CentOS-5.0 - Base                                    disabled
C5.0-centosplus             CentOS-5.0 - Plus                                    disabled
C5.0-extras                 CentOS-5.0 - Extras                                  disabled
base                        CentOS-5 - Base                                      enabled:  2,725
epel                        Extra Packages for Enterprise Linux 5 - i386         enabled:  5,783
extras                      CentOS-5 - Extras                                    enabled:    282
repolist: 20,824

17. 特定のリポジトリからパッケージをインストールする

特定の有効または無効なリポジトリから特定のパッケージをインストールするには、yumコマンドで--enablerepoオプションを使用する必要があります。たとえば、PhpMyAdminパッケージをインストールするには、次のコマンドを実行します。

# yum --enablerepo=epel install phpmyadmin

Dependencies Resolved
=============================================================================================
 Package                Arch           Version            Repository           Size
=============================================================================================
Installing:
 phpMyAdmin             noarch         3.5.1-1.el6        epel                 4.2 M

Transaction Summary
=============================================================================================
Install       1 Package(s)

Total download size: 4.2 M
Installed size: 17 M
Is this ok [y/N]: y
Downloading Packages:
phpMyAdmin-3.5.1-1.el6.noarch.rpm                       | 4.2 MB     00:25
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : phpMyAdmin-3.5.1-1.el6.noarch             1/1
  Verifying  : phpMyAdmin-3.5.1-1.el6.noarch             1/1

Installed:
  phpMyAdmin.noarch 0:3.5.1-1.el6

Complete!

18. インタラクティブなYumシェル

Yumユーティリティは、複数のコマンドを実行できるカスタムシェルを提供します。

# yum shell
Loaded plugins: fastestmirror
Setting up Yum Shell
> update httpd
Loading mirror speeds from cached hostfile
 * base: mirrors.sin3.sg.voxel.net
 * epel: ftp.riken.jp
 * extras: mirrors.sin3.sg.voxel.net
 * updates: mirrors.sin3.sg.voxel.net
Setting up Update Process
>

19. Yumキャッシュのクリーンアップ

デフォルトでは、yumは/var/cache/yum/の各サブディレクトリにリポジトリで有効になっているパッケージデータをすべて保持します。有効なリポジトリからすべてのキャッシュファイルをクリーンアップするには、不要なスペースが使用されていないことを確認し、すべてのキャッシュをクリアするために定期的に次のコマンドを実行する必要があります。以下のコマンドの出力を提供したくないので、キャッシュデータはそのままにしておきます。

# yum clean all

20. Yumの履歴の表示

yumコマンドのすべての過去のトランザクションを表示するには、次のコマンドを使用してください。

# yum history

Loaded plugins: fastestmirror
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    10 | root               | 2012-08-11 15:19 | Install        |    3
     9 | root               | 2012-08-11 15:11 | Install        |    1
     8 | root               | 2012-08-11 15:10 | Erase          |    1 EE
     7 | root               | 2012-08-10 17:44 | Install        |    1
     6 | root               | 2012-08-10 12:19 | Install        |    2
     5 | root               | 2012-08-10 12:14 | Install        |    3
     4 | root               | 2012-08-10 12:12 | I, U           |   13 E<
     3 | root               | 2012-08-09 13:01 | Install        |    1 >
     2 | root               | 2012-08-08 20:13 | I, U           |  292 EE
     1 | System            | 2012-08-08 17:15 | Install        |  560
history list

私たちは、基本的なyumコマンドから高度なものまで、それらの例を含めてカバーしようとしました。もしかしたら、yumコマンドに関連する何かが見落とされているかもしれません。コメントボックスを通じて私たちに更新をお願いします。そうすれば、フィードバックに基づいて同じ内容を更新し続けることができます。

Source:
https://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/