Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

3.5. 環境預設值

alternatives - maintain symbolic links determining default commands

3.5.1. 顯示所有配置項

			
[root@localhost ~]# alternatives --list
libwbclient.so.0.14-64	auto	/usr/lib64/samba/wbclient/libwbclient.so.0.14
ld	auto	/usr/bin/ld.bfd
cups_backend_smb	auto	/usr/bin/smbspool
mta	auto	/usr/sbin/sendmail.postfix
libnssckbi.so.x86_64	auto	/usr/lib64/pkcs11/p11-kit-trust.so
jre_1.8.0	auto	/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre
jre_1.8.0_openjdk	auto	/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
pgsql-ld-conf	auto	/usr/pgsql-11/share/postgresql-11-libs.conf
dockerd	auto	/usr/bin/dockerd-ce
java	auto	/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre/bin/java
jre_openjdk	auto	/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre
jre_11	auto	/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64
jre_11_openjdk	auto	/usr/lib/jvm/jre-11-openjdk-11.0.3.7-0.el7_6.x86_64
			
			

3.5.2. 切換版本

			
[root@localhost ~]# alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.201.b09-2.el7_6.x86_64/jre/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre/bin/java)
   3           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64/bin/java)

Enter to keep the current selection[+], or type selection number: 3		
			
			

輸入數字 3,切換到 Java 11

			
[root@localhost ~]# java -version
openjdk version "11.0.3" 2019-04-16 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.3+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.3+7-LTS, mixed mode, sharing)			
			
			

3.5.3. 使用 alternatives 管理自己的軟件版本

下面 nodejs 是編譯版本,我們需要使用 alternatives 來管理版本

			
alternatives --install /usr/local/bin/node node /srv/node-v12.3.1/bin/node  100			
			
			

查看 node

			
[root@localhost ~]# alternatives --display node
node - status is auto.
 link currently points to /srv/node-v12.3.1/bin/node
/srv/node-v12.3.1/bin/node - priority 100
Current `best' version is /srv/node-v12.3.1/bin/node.			
			
			

刪除 node

			
[root@localhost ~]# alternatives --remove node /srv/node-v12.3.1/bin/node
[root@localhost ~]# alternatives --display node