システムで使われるプログラムのバージョン管理を行うためのupdate-alternativesの使い方。
確認
# update-alternatives --display java
java - manual mode
link currently points to /usr/lib/jvm/default-java/bin/java
/usr/lib/jvm/default-java/bin/java - priority 1
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java - priority 1061
slave java.1.gz: /usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1051
slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-8-oracle/jre/bin/java - priority 1062
slave java.1.gz: /usr/lib/jvm/java-8-oracle/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-8-oracle/jre/bin/java'.
変更
# update-alternatives --config java
There are 4 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1062 auto mode
* 1 /usr/lib/jvm/default-java/bin/java 1 manual mode
2 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
3 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode
4 /usr/lib/jvm/java-8-oracle/jre/bin/java 1062 manual mode
Press enter to keep the current choice[*], or type selection number: 1
autoモード
プライオリティ値で自動的に使うものを選択するautoモードへの切り替え
# update-alternatives --auto vi
まずマニュアルで2番を選択してみる
# update-alternatives --config vi
There are 2 choices for the alternative vi (providing /usr/bin/vi).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/vim.basic 30 auto mode
1 /usr/bin/vim.basic 30 manual mode
* 2 /usr/bin/vim.tiny 10 manual mode
Press enter to keep the current choice[*], or type selection number:
root@stg-jenkins-n01:/usr/bin# update-alternatives --auto vi
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode.
その後autoモードにすると、priortyで選ばれているのがわかる
# update-alternatives --config vi
There are 2 choices for the alternative vi (providing /usr/bin/vi).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/vim.basic 30 auto mode
1 /usr/bin/vim.basic 30 manual mode
2 /usr/bin/vim.tiny 10 manual mode