iT邦幫忙

0

alternatives command not found in ubuntu

  • 分享至 

  • xImage

請教大家
參考網址https://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/# 使用下列的指令
alternatives --install /usr/bin/java java /opt/jdk1.8.0_131/bin/java 2

但會出現alternatives command not found的訊息,而我有執行過sudo apt-get update,但問題仍然一樣,煩請大家指點
謝謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
bizpro
iT邦大師 1 級 ‧ 2017-06-15 20:35:32
最佳解答

alternatives用來替換系統預設的元件. 但CentOS並未預設安裝alternatives命令.

# yum install alternatives

ektrontek iT邦研究生 1 級 ‧ 2017-06-15 22:20:28 檢舉

感謝,但我這是在ubuntu下,而我試著執行下列語法,並沒辦法更新
http://ithelp.ithome.com.tw/upload/images/20170615/20003705JY5xYSX8xo.jpg
如有其他方向指點,再請幫忙協助

bizpro iT邦大師 1 級 ‧ 2017-06-16 09:33:04 檢舉

您上個問題是在CentOS.

Ubuntu, 可以直接使用OpenJDK, 這是Oracle所用的 Hotspot JVM, 兩者的差異極小且不涉及JAVA功能, 所以是一樣的. 以下是我的安裝過程, 其中我裝了openjdk-8-jre和openjdk-9-jre, 並在兩者間用update-alternatives切換. 您也可以裝openjdk-8-jdk. 當然, 您也可以自己下載Oracle Hotspot JVM安裝.

$ sudo apt-get install openjdk-8-jre

$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.04.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

$ sudo apt-get install openjdk-9-jre

$ java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode

$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.04.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
bizpro iT邦大師 1 級 ‧ 2017-06-16 09:44:22 檢舉

您上個問題是在CentOS.

Ubuntu, 可以直接使用OpenJDK, 這是Oracle所用的 Hotspot JVM, 兩者的差異極小且不涉及JAVA功能, 所以是一樣的. 以下是我的安裝過程, 其中我裝了openjdk-8-jre和openjdk-9-jre, 並在兩者間用update-alternatives切換. 您也可以裝openjdk-8-jdk. 當然, 您也可以自己下載Oracle Hotspot JVM安裝.

$ sudo apt-get install openjdk-8-jre

$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.04.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

$ sudo apt-get install openjdk-9-jre

$ java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode

$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-0ubuntu1.16.04.2-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

而update-alternatives所做的事只是在/etc/alternatives/中建立連結:

$ ls -ls /etc/alternatives/java
0 lrwxrwxrwx 1 root root 46  6月 16 09:26 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

因此, 可以手動自行更改:

$ sudo unlink /etc/alternatives/java

$ sudo ln -s /usr/lib/jvm/java-9-openjdk-amd64/bin/java /etc/alternatives/

$ ls -ls /etc/alternatives/java
0 lrwxrwxrwx 1 root root 42  6月 16 09:40 /etc/alternatives/java -> /usr/lib/jvm/java-9-openjdk-amd64/bin/java

我要發表回答

立即登入回答