#navi(../)
* update-alternativesの対象一覧を確認する [#c71789dd]
update-alternativesコマンドでデフォルトとして使用するものを決定したり、変更したりすることができますね。~
しかし、--configなどで渡す対象となるキーワードが分からない場合などは、以下の操作により確認することができます。

#contents
#htmlinsertpcsp(linux_ads_top.html,linux-sp.html)

* alternatives設定のありか [#v9a8b2b0]
alternatives設定は、以下のディレクトリにあります。
-Debian/Ubuntu~
/var/lib/dpkg/alternatives~
- CentOS~
/var/lib/alternatives~
-openSUSE~
/var/lib/rpm/alternatives

上記のディレクトリ内にあるファイルはテキストなので、エディタを使えば設定を見ることができます。

** Debian8の出力例 [#z289d8ed]
 sakura@debian:~$ lsb_release -d
 Description:	Debian GNU/Linux 8.6 (jessie)
 sakura@debian:~$ ls -l /var/lib/dpkg/alternatives/
 合計 456
 -rw-r--r-- 1 root root  200 11月 25 22:39 appletviewer
 -rw-r--r-- 1 root root 1024 11月 25 20:59 aptitude
 -rw-r--r-- 1 root root  207 11月 25 20:20 awk
 -rw-r--r-- 1 root root   83 11月 25 20:20 builtins.7.gz
 -rw-r--r-- 1 root root   36 11月 25 21:21 c++
 -rw-r--r-- 1 root root  111 11月 25 21:21 c89
 -rw-r--r-- 1 root root  111 11月 25 21:21 c99
 -rw-r--r-- 1 root root   35 11月 25 21:21 cc
 -rw-r--r-- 1 root root   32 11月 25 21:00 cpp
 <snip>
 -rw-r--r-- 1 root root  160 11月 25 22:39 idlj
 -rw-r--r-- 1 root root  129 11月 25 21:00 infobrowser
 -rw-r--r-- 1 root root  155 11月 25 22:39 jar
 -rw-r--r-- 1 root root  185 11月 25 22:39 jarsigner
 -rw-r--r-- 1 root root  168 11月 25 21:02 java
 -rw-r--r-- 1 root root  165 11月 25 22:39 javac
 -rw-r--r-- 1 root root  175 11月 25 22:39 javadoc
 -rw-r--r-- 1 root root  165 11月 25 22:39 javah
 -rw-r--r-- 1 root root  165 11月 25 22:39 javap
 -rw-r--r-- 1 root root  160 11月 25 22:39 jcmd
 <snip>
 -rw-r--r-- 1 root root  127 11月 25 21:00 www-browser
 -rw-r--r-- 1 root root  171 11月 25 21:02 x-cursor-theme
 -rw-r--r-- 1 root root  163 11月 25 21:01 x-session-manager
 -rw-r--r-- 1 root root  389 11月 25 21:01 x-terminal-emulator
 -rw-r--r-- 1 root root  146 11月 25 21:02 x-window-manager
 -rw-r--r-- 1 root root  231 12月 14 09:50 x-www-browser
 -rw-r--r-- 1 root root  155 11月 25 22:39 xjc

* alternativesの対象 [#y3a631fb]
alternativesの対象を確認したい場合は、以下のディレクトリをlsすればよいでしょう。
 /etc/alternatives/

** Debian8の出力例 [#f4f38449]
 sakura@debian:~$ lsb_release -d
 Description:	Debian GNU/Linux 8.6 (jessie)
 sakura@debian:~$ ls -l /etc/alternatives/
 合計 28
 lrwxrwxrwx 1 root root  18 11月 25 21:00 Mail -> /usr/bin/bsd-mailx
 lrwxrwxrwx 1 root root  34 11月 25 21:00 Mail.1.gz -> /usr/share/man/man1/bsd-mailx.1.gz
 -rw-r--r-- 1 root root 100  5月  3  2016 README
 lrwxrwxrwx 1 root root  49 11月 25 22:39 appletviewer -> /usr/lib/jvm/java-7-openjdk-i386/bin/appletviewer
 lrwxrwxrwx 1 root root  59 11月 25 22:39 appletviewer.1.gz -> /usr/lib/jvm/java-7-openjdk-i386/man/man1/appletviewer.1.gz
 lrwxrwxrwx 1 root root  24 11月 25 20:59 aptitude -> /usr/bin/aptitude-curses
 lrwxrwxrwx 1 root root  40 11月 25 20:59 aptitude.8.gz -> /usr/share/man/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.cs.8.gz -> /usr/share/man/cs/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.de.8.gz -> /usr/share/man/de/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.es.8.gz -> /usr/share/man/es/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.fi.8.gz -> /usr/share/man/fi/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.fr.8.gz -> /usr/share/man/fr/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.gl.8.gz -> /usr/share/man/gl/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.it.8.gz -> /usr/share/man/it/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.ja.8.gz -> /usr/share/man/ja/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  43 11月 25 20:59 aptitude.pl.8.gz -> /usr/share/man/pl/man8/aptitude-curses.8.gz
 lrwxrwxrwx 1 root root  13 11月 25 20:19 awk -> /usr/bin/mawk
 lrwxrwxrwx 1 root root  29 11月 25 20:19 awk.1.gz -> /usr/share/man/man1/mawk.1.gz
 lrwxrwxrwx 1 root root  38 11月 25 20:20 builtins.7.gz -> /usr/share/man/man7/bash-builtins.7.gz
 lrwxrwxrwx 1 root root  12 11月 25 21:21 c++ -> /usr/bin/g++
 lrwxrwxrwx 1 root root  16 11月 25 21:21 c89 -> /usr/bin/c89-gcc
 lrwxrwxrwx 1 root root  32 11月 25 21:21 c89.1.gz -> /usr/share/man/man1/c89-gcc.1.gz
 lrwxrwxrwx 1 root root  16 11月 25 21:21 c99 -> /usr/bin/c99-gcc
 lrwxrwxrwx 1 root root  32 11月 25 21:21 c99.1.gz -> /usr/share/man/man1/c99-gcc.1.gz
 lrwxrwxrwx 1 root root  12 11月 25 21:21 cc -> /usr/bin/gcc
 lrwxrwxrwx 1 root root  12 11月 25 21:00 cpp -> /usr/bin/cpp
 lrwxrwxrwx 1 root root  60 11月 25 20:58 desktop-background -> /usr/share/images/desktop-base/lines-wallpaper_1920x1080.svg
 lrwxrwxrwx 1 root root  40 11月 25 20:58 desktop-background.xml -> /usr/share/images/desktop-base/lines.xml
 lrwxrwxrwx 1 root root  45 11月 25 20:58 desktop-grub -> /usr/share/images/desktop-base/lines-grub.png
 lrwxrwxrwx 1 root root  50 11月 25 20:58 desktop-splash -> /usr/share/images/desktop-base/spacefun-splash.svg
 lrwxrwxrwx 1 root root   9 11月 25 20:20 editor -> /bin/nano
 lrwxrwxrwx 1 root root  29 11月 25 20:20 editor.1.gz -> /usr/share/man/man1/nano.1.gz
 lrwxrwxrwx 1 root root  16 11月 25 22:09 ex -> /usr/bin/vim.nox
 <snip>

出力を見るとシンボリックリンクで切り替えているのが確認できますね。~

実際に ls /etc/alternatives/ で出力されたものをピックアップして update-alternatives --config してみます。
- x-www-browser (デフォルトブラウザの設定)
 sakura@debian:~$ sudo update-alternatives --config x-www-browser
 [sudo] password for sakura: 
 alternative x-www-browser (/usr/bin/x-www-browser を提供) には 3 個の選択肢があります。
 
   選択肢    パス                   優先度  状態
 ------------------------------------------------------------
   0            /usr/bin/vivaldi-stable   200       自動モード
   1            /usr/bin/firefox-esr      70        手動モード
 * 2            /usr/bin/midori           39        手動モード
   3            /usr/bin/vivaldi-stable   200       手動モード

-cppの設定
 sakura@debian:~$ sudo update-alternatives --config cpp
 リンクグループ cpp に 1 つの alternative のみがあります (/lib/cpp が提供): /usr/bin/cpp
 設定は行いません。

* alternativesの仕組み [#af89fdae]
例えばjavaコマンドとかはどうなっているか確認してみます。~
 ~$ which java
 /usr/bin/java
 ~$ ls -l `which java`
 lrwxrwxrwx 1 root root 22 10月 26 00:50 /usr/bin/java -> /etc/alternatives/java
 ~$ ls -l /etc/alternatives/java
 lrwxrwxrwx 1 root root 41 10月 25 17:05 /etc/alternatives/java -> /usr/lib64/jvm/jre-1.7.0-openjdk/bin/java
上記の出力をみればわかる通り、~
/usr/bin/javaは/etc/alternatives/javaで、/etc/alternatives/javaは/usr/lib64/jvm/jre-1.7.0-openjdk/bin/java(実体)であることがわかります。~
update-alternativesコマンドでシンボリックリンクを切り替えているのです。

以上、update-alternativesコマンドについての資料でした。

#htmlinsertpcsp(linux_ads_btm.html,linux-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS