LoginSignup
1
1

More than 1 year has passed since last update.

【Linux】パッケージ管理②(yum)

Posted at

yumコマンドとは

yumコマンドは、rpmパッケージを管理する為のコマンドとなります。
rpmコマンドと違い、依存関係を自動で解決してくれる・インターネット上に存在するリポジトリからrpmパッケージを入手してくれるコマンドとなります。

使用頻度はyumコマンドの方が多いと思われます。
よく使うオプションを交えて、yumコマンドを使用してみたいと思います。

試しに、httpdをインストールしようと思います。
インストール前に、httpdがインストールされていない事を確認します。
インストールされているパッケージの確認は、yumの後ろにlist installedと打てば確認出来ます。

インストールされているパッケージの確認
[root@localhost ~]# yum list installed | grep "httpd"
[root@localhost ~]#

httpdが存在しない事を確認したので、インストールしていきます。
yum install パッケージ名でインストールする事が出来ます。

下記が実行結果となります。
インストールする前に、Is this ok [y/d/N]: と確認を促されます。
yと入力すれば、インストールが開始されます。

また、httpdの依存関係となるhttpd-toolsもインストールの対象となっている事が分かります。

インストール
[root@localhost ~]# yum install httpd
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
base                                                                                                                                  | 3.6 kB  00:00:00
extras                                                                                                                                | 2.9 kB  00:00:00
updates                                                                                                                               | 2.9 kB  00:00:00
updates/7/x86_64/primary_db                                                                                                           |  20 MB  00:00:10
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd.x86_64 0:2.4.6-98.el7.centos.7 を インストール
--> 依存性の処理をしています: httpd-tools = 2.4.6-98.el7.centos.7 のパッケージ: httpd-2.4.6-98.el7.centos.7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ httpd-tools.x86_64 0:2.4.6-98.el7.centos.7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

=============================================================================================================================================================
 Package                              アーキテクチャー                バージョン                                      リポジトリー                      容量
=============================================================================================================================================================
インストール中:
 httpd                                x86_64                          2.4.6-98.el7.centos.7                           updates                          2.7 M
依存性関連でのインストールをします:
 httpd-tools                          x86_64                          2.4.6-98.el7.centos.7                           updates                           94 k

トランザクションの要約
=============================================================================================================================================================
インストール  1 パッケージ (+1 個の依存関係のパッケージ)

総ダウンロード容量: 2.8 M
インストール容量: 9.5 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): httpd-tools-2.4.6-98.el7.centos.7.x86_64.rpm                                                                                   |  94 kB  00:00:05
(2/2): httpd-2.4.6-98.el7.centos.7.x86_64.rpm                                                                                         | 2.7 MB  00:00:06
-------------------------------------------------------------------------------------------------------------------------------------------------------------
合計                                                                                                                         462 kB/s | 2.8 MB  00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : httpd-tools-2.4.6-98.el7.centos.7.x86_64                                                                                     1/2
  インストール中          : httpd-2.4.6-98.el7.centos.7.x86_64                                                                                           2/2
  検証中                  : httpd-tools-2.4.6-98.el7.centos.7.x86_64                                                                                     1/2
  検証中                  : httpd-2.4.6-98.el7.centos.7.x86_64                                                                                           2/2

インストール:
  httpd.x86_64 0:2.4.6-98.el7.centos.7

依存性関連をインストールしました:
  httpd-tools.x86_64 0:2.4.6-98.el7.centos.7

完了しました!

インストールする事が出来ました。
インストール前と同様に、yum list installedと打ち込むとインストール前とは違い、httpdhttpd-toolsが表示されました。

インストール後の確認
[root@localhost ~]# yum list installed | grep "httpd"
httpd.x86_64                          2.4.6-98.el7.centos.7            @updates
httpd-tools.x86_64                    2.4.6-98.el7.centos.7            @updates

インストールしたhttpdhttpd-toolsは検証の為にインストールしたので、アンインストールしたいと思います。
yum remove パッケージ名と実行する事で、アンインストールする事が出来ます。
インストール同様に、実行前に確認を促されます。

アンインストール
[root@localhost ~]# yum remove httpd httpd-tools
読み込んだプラグイン:fastestmirror
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd.x86_64 0:2.4.6-98.el7.centos.7 を 削除
---> パッケージ httpd-tools.x86_64 0:2.4.6-98.el7.centos.7 を 削除
--> 依存性解決を終了しました。

依存性を解決しました

=============================================================================================================================================================
 Package                              アーキテクチャー                バージョン                                     リポジトリー                       容量
=============================================================================================================================================================
削除中:
 httpd                                x86_64                          2.4.6-98.el7.centos.7                          @updates                          9.4 M
 httpd-tools                          x86_64                          2.4.6-98.el7.centos.7                          @updates                          168 k

トランザクションの要約
=============================================================================================================================================================
削除  2 パッケージ

インストール容量: 9.5 M
上記の処理を行います。よろしいでしょうか? [y/N]y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  削除中                  : httpd-2.4.6-98.el7.centos.7.x86_64                                                                                           1/2
  削除中                  : httpd-tools-2.4.6-98.el7.centos.7.x86_64                                                                                     2/2
  検証中                  : httpd-tools-2.4.6-98.el7.centos.7.x86_64                                                                                     1/2
  検証中                  : httpd-2.4.6-98.el7.centos.7.x86_64                                                                                           2/2

削除しました:
  httpd.x86_64 0:2.4.6-98.el7.centos.7                                       httpd-tools.x86_64 0:2.4.6-98.el7.centos.7

完了しました!

お次は、パッケージをアップデートしようと思います。
yum update パッケージ名で、アップデートする事が出来ます。
パッケージ名を抜いた場合は、更新可能なパッケージが全てアップデートされてしまうので注意が必要です。前準備として、yum search --showduplicates httpdで古いバージョンのhttpdの情報を取得して、インストールします。
そして、更新可能なパッケージをyum check-updateで確認します。

アップデート
#古いバージョンのhttpdをインストール
[root@localhost ~]# yum search --showduplicates httpd
[root@localhost ~]# yum install httpd-2.4.6-95.el7.centos.x86_64
[root@localhost ~]# yum list installed | grep "httpd"
httpd.x86_64                          2.4.6-95.el7.centos              @base
httpd-tools.x86_64                    2.4.6-95.el7.centos              @base

#アップデート
[root@localhost ~]# yum check-update | grep "httpd"
httpd.x86_64                       2.4.6-98.el7.centos.7                 updates
httpd-tools.x86_64                 2.4.6-98.el7.centos.7                 updates
[root@localhost ~]# yum update httpd
[root@localhost ~]# yum list installed | grep "httpd"
httpd.x86_64                          2.4.6-98.el7.centos.7            @updates
httpd-tools.x86_64                    2.4.6-98.el7.centos.7            @updates

よく使用するオプション等を下記表にまとめておきます。

コマンド 説明
list 利用可能なパッケージに関する情報を表示
list installed インストール済みのパッケージを表示
deplist 指定したパッケージの依存関係を表示
search パッケージの検索
showduplicates info、list、search コマンドでパッケージを最新バージョンに制限しない。※例えば、yum list --showduplicates | grep "httpd"とする事で古いバージョンのhttpdを確認する事が可能
check-update 更新可能なパッケージを表示
install パッケージをインストール
remove パッケージをアンインストール
update パッケージをアップデート ※パッケージ名を指定しない場合は、更新可能なパッケージが全てアップデートされてしまうので注意

以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1