GNU/Linux >> Linux の 問題 >  >> Linux

15 Linux Yum コマンドの例 – パッケージのインストール、アンインストール、更新

パッケージのインストール、削除、および更新は、Linux での一般的なアクティビティです。ほとんどの Linux ディストリビューションは、何らかのパッケージ マネージャー ユーティリティを提供しています。たとえば、apt-get、dpkg、rpm、yum などです。

一部の Linux ディストリビューションでは、yum がデフォルトのパッケージ マネージャーです。

Yum は、Yellowdog Updater Modified の略です。

この記事では、最も頻繁に使用される 15 の yum コマンドを例を挙げて説明します。

1. yum install を使用してパッケージをインストールします

パッケージをインストールするには、「yum install packagename」を実行します。これにより、依存関係も自動的に識別され、インストールされます。

次の例では、postgresql パッケージをインストールします。

# yum install postgresql.x86_64
Resolving Dependencies
Install       2 Package(s)
Is this ok [y/N]: y

Package(s) data still to download: 3.0 M
(1/2): postgresql-9.0.4-5.fc15.x86_64.rpm          | 2.8 MB     00:11
(2/2): postgresql-libs-9.0.4-5.fc15.x86_64.rpm    | 203 kB     00:00
------------------------------------------------------------------
Total                                        241 kB/s | 3.0 MB     00:12     

Running Transaction
  Installing : postgresql-libs-9.0.4-5.fc15.x86_64             1/2
  Installing : postgresql-9.0.4-5.fc15.x86_64                   2/2 

Complete!

デフォルトの「yum install」では、パッケージをインストールする前に、受け入れるか拒否するかを尋ねられます。プロンプトを表示せずに yum を自動的にインストールする場合は、以下に示すように -y オプションを使用します。

# yum -y install postgresql.x86_64

2. yum remove を使用してパッケージをアンインストール

パッケージを (すべての依存関係と共に) 削除するには、以下に示すように「yum remove package」を使用します。

# yum remove  postgresql.x86_64
Resolving Dependencies
---> Package postgresql.x86_64 0:9.0.4-5.fc15 will be erased

Is this ok [y/N]: y

Running Transaction
  Erasing    : postgresql-9.0.4-5.fc15.x86_64       1/1 

Removed:
  postgresql.x86_64 0:9.0.4-5.fc15

Complete!

3. yum update を使用して既存のパッケージをアップグレードする

古いバージョンのパッケージがある場合は、「yum update package」を使用して最新の現在のバージョンにアップグレードします。これにより、必要なすべての依存関係も特定され、インストールされます。

# yum update postgresql.x86_64

4. yum search を使用してインストールするパッケージを検索します

インストールする正確なパッケージ名がわからない場合は、「yum 検索キーワード」を使用してください。これにより、「キーワード」に一致するすべてのパッケージが検索され、表示されます。

次の例では、キーワード「firefox」に一致するすべてのパッケージを yum リポジトリで検索し、利用可能なパッケージを一覧表示します。

# yum search firefox
Loaded plugins: langpacks, presto, refresh-packagekit
============== N/S Matched: firefox ======================
firefox.x86_64 : Mozilla Firefox Web browser
gnome-do-plugins-firefox.x86_64 : gnome-do-plugins for firefox
mozilla-firetray-firefox.x86_64 : System tray extension for firefox
mozilla-adblockplus.noarch : Adblocking extension for Mozilla Firefox
mozilla-noscript.noarch : JavaScript white list extension for Mozilla Firefox

Name and summary matches only, use "search all" for everything.

5. yum info を使用してパッケージに関する追加情報を表示する

yum 検索を使用してパッケージを検索したら、「yum info package」を使用してパッケージに関する追加情報を表示できます。

次の例は、samba-common パッケージに関する追加情報を示しています。

# yum info samba-common.i686
Loaded plugins: langpacks, presto, refresh-packagekit
Available Packages
Name        : samba-common
Arch        : i686
Epoch       : 1
Version     : 3.5.11
Release     : 71.fc15.1
Size        : 9.9 M
Repo        : updates
Summary     : Files used by both Samba servers and clients
URL         : http://www.samba.org/
License     : GPLv3+ and LGPLv3+
Description : Samba-common provides files necessary for both the server and client
            : packages of Samba.

6. yum list を使用して利用可能なすべてのパッケージを表示

次のコマンドは、yum データベースで利用可能なすべてのパッケージを一覧表示します。

# yum list | less

7. yum list installed を使用して、インストールされているパッケージのみを一覧表示します

システムにインストールされているすべてのパッケージを表示するには、次の yum コマンドを実行します。

# yum list installed | less

8.ファイルはどのパッケージに属していますか? – yum provides を使用

特定のファイルがどのパッケージに属しているかを知りたい場合は、「yum provides」を使用してください。たとえば、/etc/sysconfig/nfs ファイルを含むパッケージの名前を知りたい場合は、次のようにします。

# yum provides /etc/sysconfig/nfs
Loaded plugins: langpacks, presto, refresh-packagekit
1:nfs-utils-1.2.3-10.fc15.x86_64 : NFS utilities and supporting clients and
                                 : daemons for the kernel NFS server
Repo        : fedora
Matched from:
Filename    : /etc/sysconfig/nfs

1:nfs-utils-1.2.4-1.fc15.x86_64 : NFS utilities and supporting clients and
                                : daemons for the kernel NFS server
Repo        : updates
Matched from:
Filename    : /etc/sysconfig/nfs

1:nfs-utils-1.2.4-1.fc15.x86_64 : NFS utilities and supporting clients and
                                : daemons for the kernel NFS server
Repo        : installed
Matched from:
Other       : Provides-match: /etc/sysconfig/nfs

9. yum grouplist を使用して利用可能なソフトウェア グループを一覧表示

yum では、関連する複数のパッケージが特定のグループにグループ化されます。特定の機能に属する個々のパッケージをすべて検索してインストールする代わりに、グループをインストールするだけで、グループに属するすべてのパッケージがインストールされます。

利用可能なすべてのソフトウェア グループを表示するには、以下に示すように「yum grouplist」を実行します。出力は、Installed Groups、Installed Language Groups、Available Groups の 3 つのグループに一覧表示されます。

# yum grouplist

Installed Groups:
   Administration Tools
   Base
   Design Suite
   ....

Installed Language Groups:
   Arabic Support [ar]
   Armenian Support [hy]
   Bengali Support [bn]
   ....

Available Groups:
   Authoring and Publishing
   Books and Guides
   Clustering
   DNS Name Server
   Development Libraries
   Development Tools
   Directory Server
   Dogtag Certificate System
   ...

10. yum groupinstall を使用して特定のソフトウェア グループをインストールします

特定のソフトウェア グループをインストールするには、以下に示すように groupinstall オプションを使用します。次の例では、「DNS Name Server」グループに bind と bind-chroot が含まれています。

# yum groupinstall 'DNS Name Server'

Dependencies Resolved
Install       2 Package(s)
Is this ok [y/N]: y

Package(s) data still to download: 3.6 M
(1/2): bind-9.8.0-9.P4.fc15.x86_64.rpm             | 3.6 MB     00:15
(2/2): bind-chroot-9.8.0-9.P4.fc15.x86_64.rpm   |  69 kB     00:00
-----------------------------------------------------------------
Total               235 kB/s | 3.6 MB     00:15

Installed:
  bind-chroot.x86_64 32:9.8.0-9.P4.fc15

Dependency Installed:
  bind.x86_64 32:9.8.0-9.P4.fc15

Complete!

注:前に説明したように、yum groupinstall を使用して MySQL データベースをインストールすることもできます。

11. groupupdate を使用して既存のソフトウェア グループをアップグレードする

yum groupinstall を使用して既にソフトウェア グループをインストールしており、それを最新バージョンにアップグレードしたい場合は、以下に示すように「yum groupupdate」を使用してください。

# yum groupupdate 'Graphical Internet'

Dependencies Resolved
Upgrade       5 Package(s)
Is this ok [y/N]: y   

Running Transaction
  Updating   : evolution-data-server-3.0.2-1.fc15.x86_64     1/10
  Updating   : evolution-3.0.2-3.fc15.x86_64                 2/10
  Updating   : evolution-NetworkManager-3.0.2-3.fc15.x86_64  3/10
  Updating   : evolution-help-3.0.2-3.fc15.noarch            4/10
  Updating   : empathy-3.0.2-3.fc15.x86_64                   5/10
  Cleanup    : evolution-NetworkManager-3.0.1-1.fc15.x86_64  6/10
  Cleanup    : evolution-help-3.0.1-1.fc15.noarch            7/10
  Cleanup    : evolution-3.0.1-1.fc15.x86_64                 8/10
  Cleanup    : empathy-3.0.1-3.fc15.x86_64                   9/10
  Cleanup    : evolution-data-server-3.0.1-1.fc15.x86_64     10/10 

Complete!

12. yum groupremove を使用してソフトウェア グループをアンインストールします

既存のソフトウェア グループを削除するには、以下に示すように「yum groupremove」を使用します。

# yum groupremove 'DNS Name Server'
Dependencies Resolved
Remove        2 Package(s)
Is this ok [y/N]: y

Running Transaction
  Erasing    : 32:bind-chroot-9.8.0-9.P4.fc15.x86_64  1/2
  Erasing    : 32:bind-9.8.0-9.P4.fc15.x86_64            2/2 

Complete!

13.現在の yum リポジトリを表示

すべての yum コマンドは、1 つ以上の yum リポジトリーに対して実行されます。システムで構成されているすべての yum リポジトリを表示するには、以下に示すように「yum repolist」を実行します。

以下は、有効なリポジトリのみを表示します。

# yum repolist
repo id     repo name                        status
fedora      Fedora 15 - x86_64               24,085
updates     Fedora 15 - x86_64 - Updates     5,612

すべてのリポジトリ (有効と無効の両方) を表示するには、「yum repolist all」を使用します。

# yum repolist all
repo id                   repo name                                status
fedora                    Fedora 15 - x86_64                       enabled: 24,085
fedora-debuginfo          Fedora 15 - x86_64 - Debug               disabled
fedora-source             Fedora 15 - Source                       disabled
rawhide-debuginfo         Fedora - Rawhide - Debug                 disabled
rawhide-source            Fedora - Rawhide - Source                disabled
updates                   Fedora 15 - x86_64 - Updates             enabled:  5,612
updates-debuginfo         Fedora 15 - x86_64 - Updates - Debug     disabled
updates-source            Fedora 15 - Updates Source               disabled
updates-testing           Fedora 15 - x86_64 - Test Updates        disabled
updates-testing-debuginfo Fedora 15 - x86_64 - Test Updates Debug  disabled
updates-testing-source    Fedora 15 - Test Updates Source          disabled

無効なリポジトリのみを表示するには、「yum repositories disabled」を使用してください。

14. yum –enablerepo を使用して無効なリポジトリからインストールします

デフォルトでは、有効なリポジトリからのみ yum がインストールされます。何らかの理由で、無効なリポジトリからパッケージをインストールしたい場合は、以下に示すように「yum install」で –enablerepo オプションを使用してください。

# yum --enablerepo=fedora-source install vim-X11.x86_64
Dependencies Resolved
Install       1 Package(s)
Is this ok [y/N]: y

Running Transaction
  Installing : 2:vim-X11-7.3.138-1.fc15.x86_64   1/1 

Complete!

15. Yum Shell を使用してインタラクティブに yum コマンドを実行する

Yum は、以下に示すように、複数のコマンドを実行するための対話型シェルを提供します。

# yum shell
Setting up Yum Shell
> info samba.x86_64
Available Packages
Name        : samba
Arch        : x86_64
Epoch       : 1
Version     : 3.5.11
Release     : 71.fc15.1
Size        : 4.6 M
Repo        : updates
Summary     : Server and Client software to interoperate with Windows machines
URL         : http://www.samba.org/
License     : GPLv3+ and LGPLv3+
Description :
            : Samba is the suite of programs by which a lot of PC-related
            : machines share files, printers, and other information (such as
            : lists of available files and printers). The Windows NT, OS/2, and
            : Linux operating systems support this natively, and add-on packages
            : can enable the same thing for DOS, Windows, VMS, UNIX of all
            : kinds, MVS, and more. This package provides an SMB/CIFS server
            : that can be used to provide network services to SMB/CIFS clients.
            : Samba uses NetBIOS over TCP/IP (NetBT) protocols and does NOT
            : need the NetBEUI (Microsoft Raw NetBIOS frame) protocol.

> 

Yum は、テキスト ファイルからコマンドを読み取り、1 つずつ実行することもできます。これは、複数のシステムがある場合に非常に役立ちます。すべてのシステムで同じコマンドを実行する代わりに、それらのコマンドを含むテキスト ファイルを作成し、以下に示すように「yum シェル」を使用してそれらのコマンドを実行します。

# cat yum_cmd.txt
repolist
info nfs-utils-lib.x86_64

# yum shell yum_cmd.txt 
repo id     repo name                        status
fedora      Fedora 15 - x86_64               24,085
updates     Fedora 15 - x86_64 - Updates     5,612

Available Packages
Name        : nfs-utils-lib
Arch        : x86_64
Version     : 1.1.5
Release     : 5.fc15
Size        : 61 k
Repo        : fedora
Summary     : Network File System Support Library
URL         : http://www.citi.umich.edu/projects/nfsv4/linux/
License     : BSD
Description : Support libraries that are needed by the commands and
            : daemons the nfs-utils rpm.

Leaving Shell

Linux
  1. 7 Linux df コマンドの例

  2. パッケージをインストール、削除、およびアップグレードするための YUM コマンドの例

  3. Linux での sa コマンドの例

  1. 8 Linux TR コマンドの例

  2. Linux でのパッケージ管理のための 15 の aptitude コマンドの例

  3. SUSE Linux でパッケージを管理する 20 の Zypper コマンドの例

  1. パッケージを照会、インストール、削除、およびアップグレードするための RPM コマンドの例

  2. Linux での rm コマンドの例

  3. Linux での ps コマンドの例