技術者になりたい何か

技術者になりたい何かの覚書的な何かです

Linuxのパッケージ管理しりーず(yum)

yumRed Hat系のパッケージ管理コマンド。

リポジトリ経由のあれやこれやに使う。実際のサーバ運用とか構築でパッケージ入れたり更新したり削除したりみたいな時には主にこれでやることが多い。

 

yum rpmパッケージの管理

Red Hat系で使われるパッケージ管理コマンド。

リポジトリ参照してインストール・アンインストール、アップデート、パッケージの検索など、
大抵のことはできる。
基本的に普通にCentOSを使うとした場合、yumによるパッケージ管理で事足りる。

基本的な使い方

# yum サブコマンド [パッケージ名]

 

主なサブコマンド

check-update アップデート対象のパッケージリストを表示。アップデート前のチェックとかに使う。
update パッケージ名 指定したパッケージをアップデートする。パッケージ指定しないときはアップデートがあるパッケージを全て更新する。
install パッケージ名 指定したパッケージをインストールする。
remove パッケージ名 指定したパッケージをアンインストールする。
info パッケージ名 指定したパッケージの情報を表示する。バージョンとか確認するのに便利。
list 全パッケージの情報をリスト表示する。
repolist リポジトリ一覧情報を表示する。
search キーワード パッケージ情報をキーワードで検索する。
search all キーワード パッケージをパッケージ名、説明文全て対象にキーワードで検索する。
grouplist パッケージグループをリスト表示する
groupinstall 指定したグループのパッケージをインストールする。
clean リポジトリからダウンロードしたヘッダーファイルとパッケージを削除する。

実行例

yum check-update
 
$ yum check-update
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.kddilabs.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp

ImageMagick.x86_64 6.7.2.7-2.el6 base
ImageMagick-devel.x86_64 6.7.2.7-2.el6 base
NetworkManager.x86_64 1:0.8.1-99.el6 base
NetworkManager-glib.x86_64 1:0.8.1-99.el6 base
NetworkManager-gnome.x86_64 1:0.8.1-99.el6 base
PackageKit.x86_64 0.5.8-25.el6 base
PackageKit-device-rebind.x86_64 0.5.8-25.el6 base
PackageKit-glib.x86_64 0.5.8-25.el6 base
PackageKit-gstreamer-plugin.x86_64 0.5.8-25.el6

 

check-updateでは更新を確認するだけで、実際に更新はされない。
そのため、常時稼働のサーバーなどでもこれは実行しても直ちにサービスに影響が出ることは無い。
大抵の場合、あまり止めたくないサーバーの更新前チェックなどに使う。
ちなみにあまり気を遣わなくても良いシステムでは、下記のupdateをいきなり実行するのもありではある。

yum update
 

# yum update
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
更新処理の設定をしています
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.iij.ad.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> Package ImageMagick.x86_64 0:6.5.4.7-7.el6_5 will be 更新
---> Package ImageMagick.x86_64 0:6.7.2.7-2.el6 will be an update
--> 依存性の処理をしています: libwmf-0.2.so.7()(64bit) のパッケージ: ImageMagick-6.7.2.7-2.el6.x86_64
---> Package ImageMagick-devel.x86_64 0:6.5.4.7-7.el6_5 will be 更新
---> Package ImageMagick-devel.x86_64 0:6.7.2.7-2.el6 will be an update
---> Package NetworkManager.x86_64 1:0.8.1-75.el6 will be 更新

(中略)

依存性を解決しました

============================================================================================================================================
パッケージ アーキテクチャ
バージョン リポジトリー 容量
============================================================================================================================================
インストールしています:
kernel x86_64 2.6.32-573.12.1.el6 updates 30 M
kernel-devel x86_64 2.6.32-573.12.1.el6 updates 10 M
更新:
ImageMagick x86_64 6.7.2.7-2.el6 base 1.9 M
ImageMagick-devel x86_64 6.7.2.7-2.el6 base 94 k
NetworkManager x86_64 1:0.8.1-99.el6 base 1.1 M
NetworkManager-glib x86_64 1:0.8.1-99.el6 base
(中略)

トランザクションの要約
============================================================================================================================================
インストール 13 パッケージ
アップグレード 364 パッケージ
削除 2 パッケージ

総ダウンロード容量: 515 M
これでいいですか? [y/N]y

(中略)
完了しました!

 

実際にupdateをかけると、更新した際の依存関係が解決できるかをまず検証する。
次に新規インストールになるもの、更新になるものがリスト表示され、
(たぶん多数のupdateがあるときには)同意を求められる。
ここで y を入力すると、実際にパッケージをダウンロード→インストールという動作を行う。
ちなみに -y を付けることで、この同意を求める部分をスキップすることも可能である。

yum info

$ yum info openssl
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.jaist.ac.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
インストール済みパッケージ
名前 : openssl
アーキテクチャ : x86_64
バージョン : 1.0.1e
リリース : 42.el6_7.2
容量 : 4.0 M
リポジトリー : installed
提供元リポジトリー : updates
要約 : A general purpose cryptography library with TLS implementation
URL : http://www.openssl.org/
ライセンス : OpenSSL
説明 : The OpenSSL toolkit provides support for secure communications between
: machines. OpenSSL includes a certificate management tool and shared
: libraries which provide various cryptographic algorithms and
: protocols.

利用可能なパッケージ
名前 : openssl
アーキテクチャ : i686
バージョン : 1.0.1e
リリース : 42.el6_7.2
容量 : 1.5 M
リポジトリー : updates
要約 : A general purpose cryptography library with TLS implementation
URL : http://www.openssl.org/
ライセンス : OpenSSL
説明 : The OpenSSL toolkit provides support for secure communications between
: machines. OpenSSL includes a certificate management tool and shared
: libraries which provide various cryptographic algorithms and
: protocols.

 

上記例ではopensslというパッケージの情報を表示している。
基本的に詳細が出るので見ればわかる感じではある。
更新がある(より新しいパッケージがリポジトリに降りてきている)ときは
インストール済みと利用可能のバージョンを見ればよいだろう。
あるパッケージで脆弱性が見つかったなどして、特定のパッケージのみ急いでupdateしなくてはいけないが、
システム全体のアップデートをする(ものによってはプロセスなりそのシステム自体の再起動が必要)のは避けたい、
みたいなときの下調べに使える。

これで確認した後、更新が見つかればそのパッケージ名指定でupdateをかけるという事が可能。

# yum update openssl


この場合、opensslのみupdateをする。

yum list

$ yum list
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
Determining fastest mirrors
epel/metalink | 5.3 kB 00:00
* base: www.ftp.ne.jp
* epel: ftp.riken.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
WANdisco | 951 B 00:00
WANdisco 73/73
adobe-linux-x86_64 | 951 B 00:00
base | 3.7 kB 00:00
emacs | 2.9 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
インストール済みパッケージ
Canna-libs.x86_64 3.7p3-28.el6 @epel
ConsoleKit.x86_64 0.4.1-3.el6 @anaconda-CentOS-201311291202.x86_64/6.5
ConsoleKit-libs.x86_64 0.4.1-3.el6 @anaconda-CentOS-201311291202.x86_64/6.5
ConsoleKit-x11.x86_64 0.4.1-3.el6 @anaconda-CentOS-201311291202.x86_64/6.5
DeviceKit-power.x86_64 014-3.el6 @anaconda-CentOS-201311291202.x86_64/6.5

(中略)
利用可能なパッケージ
2048-cli.x86_64 0.9.1-1.el6 epel
2048-cli-nocurses.x86_64 0.9.1-1.el6 epel
2ping.noarch 3.2.1-2.el6 epel
389-admin.i686 1.1.35-1.el6 epel
389-admin.x86_64 1.1.35-1.el6 epel
389-admin-console.noarch 1.1.8-1.el6 epel
389-admin-console-doc.noarch 1.1.8-1.el6 epel
389-adminutil.i686 1.1.19-1.el6 epel
389-adminutil.x86_64 1.1.19-1.el6 epel
389-adminutil-devel.i686 1.1.19-1.el6 epel
389-adminutil-devel.x86_64 1.1.19-1.el6 epel
389-console.noarch 1.1.7-1.el6 epel
(以下略)

 

 

大量に出る。
リポジトリ参照→インストール済みリスト→利用可能パッケージの「全て」を表示する。
grepとかに渡せばいい仕事してくれるかもしれないが、ぶっちゃけ見切れる気がしない。
また、grepするくらいなら下記searchとか上記infoとかを使った方がいいだろう。
まぁインストールしてるパッケージをログとして保存しておくにはいいかもしれないが。

yum search

$ yum search httpd
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.riken.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
============================================================ N/S Matched: httpd ============================================================
iipsrv-httpd-fcgi.noarch : Apache HTTPD files for iipsrv
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
lighttpd-fastcgi.x86_64 : FastCGI module and spawning helper for lighttpd and PHP configuration
lighttpd-mod_geoip.x86_64 : GeoIP module for lighttpd to use for location lookups
lighttpd-mod_mysql_vhost.x86_64 : Virtual host module for lighttpd that uses a MySQL database
owncloud-httpd.noarch : Httpd integration for ownCloud
httpd.x86_64 : Apache HTTP Server
httpd-devel.i686 : Development interfaces for the Apache HTTP server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-itk.x86_64 : MPM Itk for Apache HTTP Server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
lighttpd.x86_64 : Lightning fast webserver with light system requirements
mirmon-httpd.noarch : Apache configuration for mirmon
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
mod_dnssd.x86_64 : An Apache HTTPD module which adds Zeroconf support
python-mozhttpd.noarch : Basic Python webserver
python-sphinxcontrib-httpdomain.noarch : Sphinx domain for documenting HTTP APIs
sysusage-httpd.noarch : Apache configuration for sysusage
thttpd.x86_64 : Tiny, turbo, throttleable lightweight http server
viewvc-httpd.noarch : ViewVC configuration for Apache/mod_python
web-assets-httpd.noarch : Web Assets aliases for the Apache HTTP daemon

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

 


httpdで検索。パッケージ名にhttpdが入っているものを表示する。
入れたいパッケージないし入っているパッケージで正式名称が判らなくなってしまったときに便利。

yum search all

$ yum search-all httpd
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
コマンド「search-all」が見つかりません。「/usr/bin/yum --help」を実行してください。
[cmc@redmine-svn-serv ~]$ yum search all httpd
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.riken.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
=============================================================== 一致: httpd ================================================================
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
lighttpd-fastcgi.x86_64 : FastCGI module and spawning helper for lighttpd and PHP configuration
lighttpd-mod_geoip.x86_64 : GeoIP module for lighttpd to use for location lookups
lighttpd-mod_mysql_vhost.x86_64 : Virtual host module for lighttpd that uses a MySQL database
(中略)
qgis-mapserver.x86_64 : FCGI based OGC web map server
spawn-fcgi.x86_64 : Simple program for spawning FastCGI processes
sysusage-httpd.noarch : Apache configuration for sysusage
trafficserver-devel.i686 : Apache Traffic Server development libraries and header files
trafficserver-devel.x86_64 : Apache Traffic Server development libraries and header files
viewvc-httpd.noarch : ViewVC configuration for Apache/mod_python
web-assets-httpd.noarch : Web Assets aliases for the Apache HTTP daemon
xcache-admin.noarch : XCache Administration


最後の方を見ると分かるが、パッケージ名にhttpdが入っていないものも表示される。
これは説明文の中にhttpdが入っているから。

httpdが含まれなかった「xcache-admin.noarch」を見てみよう。

$ yum info xcache-admin.noarch
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.riken.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
利用可能なパッケージ
名前 : xcache-admin
アーキテクチャ : noarch
バージョン : 3.0.4
リリース : 1.el6
容量 : 46 k
リポジトリー : epel
要約 : XCache Administration
URL : http://xcache.lighttpd.net/
ライセンス : BSD
説明 : This package provides the XCache Administration web application,
: with Apache configuration, on http://localhost/xcache
:
: This requires to configure, in XCache configuration file (xcache.ini):
: - xcache.admin.user
: - xcache.admin.pass
: - xcache.coveragedump_directory


なんということだ。URLの中のlig*httpd*.netに反応してるじゃないか。(たぶん)

yum grouplist

$ yum grouplist
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
グループ処理の設定をしています
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.riken.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
インストール済みグループ:
Emacs
FTP サーバー
Java プラットフォーム
Milkymist
MySQL データベースサーバー
MySQL データベース接続クライアント
PHP サポート
Perl のサポート
(以下省略)


ある環境を構築したいときにグループで関連パッケージ全部入れられると便利だよねー、というコマンド。
MySQL データベースサーバー」とかだとmySQLサーバー構築に必要なパッケージ丸ごとインストールしてくれる。
サーバー構築時に必要な環境(WebサーバーとしてPHPApacheMySQLをいれよう)とかいうときに便利かもしれない。
ただし、実際には不必要なパッケージも一緒に入ってくることはままある。(Gnomeデスクトップ環境入れたら付属のミニゲームが入ってくるとか)
しかい、これって日本語化されてて大丈夫なのか?⇒大丈夫っぽい

yum groupinstall


上記グループ丸ごとインストールしたいときに使う。
環境を一気の整えられるので楽できる反面、本当に必要なパッケージのみ選択して入れるという事は出来ない為、好みが分かれるところ。
実行例

$ sudo yum groupinstall "KDE デスクトップ"
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
グループ処理の設定をしています
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* epel: ftp.riken.jp
* extras: ftp.riken.jp
* updates: ftp.riken.jp
パッケージ alsa-plugins-pulseaudio-1.0.21-3.el6.x86_64 はインストール済みか最新バージョンです
パッケージ 1:NetworkManager-gnome-0.8.1-99.el6.x86_64 はインストール済みか最新バージョンです
パッケージ ibus-qt-1.3.0-2.el6.x86_64 はインストール済みか最新バージョンです
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> Package k3b.x86_64 1:1.0.5-13.el6 will be インストール
--> 依存性の処理をしています: k3b-libs(x86-64) = 1:1.0.5-13.el6 のパッケージ: 1:k3b-1.0.5-13.el6.x86_64
--> 依存性の処理をしています: k3b-common = 1:1.0.5-13.el6 のパッケージ: 1:k3b-1.0.5-13.el6.x86_64
--> 依存性の処理をしています: libmusicbrainz.so.4()(64bit) のパッケージ: 1:k3b-1.0.5-13.el6.x86_64
--> 依存性の処理をしています: libkparts.so.2()(64bit) のパッケージ: 1:k3b-1.0.5-13.el6.x86_64
(中略)
依存性を解決しました

============================================================================================================================================
パッケージ アーキテクチャ バージョン リポジトリー 容量
============================================================================================================================================
インストールしています:
k3b x86_64 1:1.0.5-13.el6 base 758 k
kcoloredit x86_64 4.3.3-2.el6 base 165 k
kde-settings-pulseaudio noarch 4.3.1-2.el6.centos base 16 k
kdeaccessibility x86_64 1:4.3.4-5.el6 base 6.1 M
kdeadmin x86_64 7:4.3.4-5.el6 base 1.3 M
kdeartwork-screensavers x86_64 4.3.4-7.el6 base 386 k
kdebase x86_64 6:4.3.4-7.el6_7 updates 4.5 M
kdebase-workspace x86_64 4.3.4-33.el6_7 updates 12 M
kdegames x86_64 6:4.3.4-5.el6 base 41 M
kdegraphics x86_64 7:4.3.4-6.el6 base 3.0 M
kdelibs x86_64 6:4.3.4-24.el6_7 updates 11 M
(中略)
トランザクションの要約
============================================================================================================================================
インストール 102 パッケージ

総ダウンロード容量: 239 M
インストール済み容量: 544 M
これでいいですか? [y/N]

 


この場合、KDEデスクトップ環境を一気に整えられる。
しかしk3bとか、CD、DVDのツールだろ別にKDE環境欲しいだけならいらないじゃん、みたいなことがままある。

・clean


updateが途中で止まってしまったりしてリポジトリや依存関係がおかしくなってしまったときに
yumが保存しているキャッシュを削除するとなおるときもあったりする。
ちなみにキャッシュは/var/cache/yumにある。

$ du -sh /var/cache/yum

521M /var/cache/yum

$ sudo yum clean all

 読み込んだプラグイン:fastestmirror, refresh-packagekit, security

リポジトリーを清掃しています: WANdisco adobe-linux-x86_64 base emacs epel extras updates
すべて掃除しています
Cleaning up list of fastest mirrors

$ du -sh /var/cache/yum
14M /var/cache/yum

$ ls /var/cache/yum/
timedhosts.txt x86_64

$ yum check-update
読み込んだプラグイン:fastestmirror, refresh-packagekit, security
(以下略)
$ sudo yum update
(以下略)

$ du -sh /var/cache/yum
100M /var/cache/yum

 

おまけ


パッケージファイルのダウンロードだけしてインストールはしない。


yumdownloader

$ yumdownloader zsh
読み込んだプラグイン:fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* epel: ftp.riken.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
zsh-4.3.11-4.el6.centos.2.x86_64.rpm | 2.2 MB 00:00

 

Sponsored Link