ウェブサイト検索

Linux パッケージ管理のための 20 の YUM コマンド


この記事では、< によって開発された YUM (Yellowdog Updater Modified) ツールを使用して、Linux システム上でパッケージをインストール、更新、削除、検索し、パッケージとリポジトリを管理する方法を学びます。strong>レッドハットです。

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

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

ヤムって何ですか?

YUM (Yellowdog Updater Modified) は、RPM ( 用のオープンソースのコマンドラインおよびグラフィカルベースのパッケージ管理ツール) です。 RedHat パッケージ マネージャー) ベースの Linux システム。

これにより、ユーザーとシステム管理者は、システム上のソフトウェア パッケージを簡単にインストール、更新、削除、検索できます。これは、Seth Vidal によってオープンソースとしてGPL (一般公衆利用許諾) に基づいて開発およびリリースされました。つまり、誰でもダウンロードできるということです。コードにアクセスしてバグを修正し、カスタマイズされたパッケージを開発します。

YUM は、多数のサードパーティ リポジトリを使用して、依存関係の問題を解決することでパッケージを自動的にインストールします。

更新: yum コマンドは、yum の次世代バージョンであり、yum の代替となる dnf コマンドに置き換えられます。ほとんどの新しい 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 を使用します。

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を使用してパッケージを一覧表示する

リスト関数を使用して、名前付きの特定のパッケージを検索します。たとえば、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

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 のprovides関数は、特定のファイルがどのパッケージに属しているかを見つけるために使用されます。たとえば、/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 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 コマンドに関連するものが欠落している可能性があります。コメントボックスを通じて最新情報をお知らせください。したがって、受け取ったフィードバックに基づいて同じものを更新し続けます。