感谢支持
我们一直在努力

OpenSUSE下安装JDK

openSUSE自带了OpenJDK,安装Oracle JDK后,需要使用alternatives切换系统默认使用的JDK版本。

1)安装JDK:

linuxidc@linux-linuxidc:~/下载> sudo zypper install jdk-8u66-linux-x64.rpm -y 

/var/tmp/rpm-tmp.DfGrcZ: line 638: /usr/sbin/alternatives: No such file or directory
/var/tmp/rpm-tmp.DfGrcZ: line 650: /usr/sbin/alternatives: No such file or directory
warning: %post(jdk1.8.0_66-2000:1.8.0_66-fcs.x86_64) scriptlet failed, exit status 127

有如上的报错,“/usr/sbin/alternatives”这个文件找不到。openSUSE相应的文件名是update-alternatives,尝试做了软连接,会报新的错误:

update-alternatives: error: alternative javaws can’t be slave of java: it is a slave of javaplugin
update-alternatives: error: alternative javaws can’t be slave of javac: it is a slave of javaplugin
warning: %post(jdk1.8.0_66-2000:1.8.0_66-fcs.x86_64) scriptlet failed, exit status 2

看来openSUSE和Oracle JDK不是很友好啊,需要手动完成后续的必要步骤(从网上找的,可能不是安装脚本的全部后续操作)。

2)用alternatives声明jdk版本并设为默认:

linuxidc@linux-linuxidc:~/下载> sudo /usr/sbin/update-alternatives –install “/usr/bin/java” “java” “/usr/java/jdk1.8.0_66/bin/java” 40
linuxidc@linux-linuxidc:~/下载> sudo /usr/sbin/update-alternatives –install “/usr/lib64/browser-plugins/javaplugin.so” “javaplugin” “/usr/java/jdk1.8.0_66/jre/lib/amd64/libnpjp2.so” 40

——其中红色部分根据操作系统及指令集不同会有不同。

linuxidc@linux-linuxidc:~/下载> sudo /usr/sbin/update-alternatives –config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                      Priority  Status
————————————————————
* 0            /usr/lib64/jvm/jre-1.8.0-openjdk/bin/java  18040    auto mode
  1            /usr/java/jdk1.8.0_66/bin/java              40        manual mode
  2            /usr/lib64/jvm/jre-1.7.0-openjdk/bin/java  17147    manual mode
  3            /usr/lib64/jvm/jre-1.8.0-openjdk/bin/java  18040    manual mode

Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/java/jdk1.8.0_66/bin/java to provide /usr/bin/java (java) in manual mode
linuxidc@linux-linuxidc:~/下载> sudo /usr/sbin/update-alternatives –config javaplugin
There are 3 choices for the alternative javaplugin (providing /usr/lib64/browser-plugins/javaplugin.so).

  Selection    Path                                                      Priority  Status
————————————————————
* 0            /usr/lib64/java-1_8_0-openjdk-plugin/lib/IcedTeaPlugin.so  18020    auto mode
  1            /usr/java/jdk1.8.0_66/jre/lib/amd64/libnpjp2.so            40        manual mode
  2            /usr/lib64/java-1_7_0-openjdk-plugin/lib/IcedTeaPlugin.so  17147    manual mode
  3            /usr/lib64/java-1_8_0-openjdk-plugin/lib/IcedTeaPlugin.so  18020    manual mode

Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/java/jdk1.8.0_66/jre/lib/amd64/libnpjp2.so to provide /usr/lib64/browser-plugins/javaplugin.so (javaplugin) in manual mode

3)查看JDK版本:
linuxidc@linux-linuxidc:~/下载> java -version
java version “1.8.0_66”

4)修改JAVA_HOME:

但是此时JAVA_HOME尚不正确:

linuxidc@linux-linuxidc:~/下载> echo $JAVA_HOME
/usr/lib64/jvm/jre

修改/etc/profile文件,在文件尾追加:

export JAVA_HOME=/usr/java/jdk1.8.0_66
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

退出,重新登陆后:

linuxidc@linux-linuxidc:~> echo $JAVA_HOME
/usr/java/jdk1.8.0_66

DONE!

Ubuntu 14.04安装JDK1.8.0_25与配置环境变量 http://www.linuxidc.com/Linux/2015-01/112030.htm 

CentOS 搭建JDK环境  http://www.linuxidc.com/Linux/2015-06/118879.htm 

Ubuntu 14.04安装JDK1.8.0_25与配置环境变量  http://www.linuxidc.com/Linux/2015-01/112030.htm 

Ubuntu 14.04 LTS安装Oracle JDK 1.8  http://www.linuxidc.com/Linux/2014-11/109216.htm 

CentOS6.3安装JDK和环境配置 http://www.linuxidc.com/Linux/2012-09/70780.htm 

Ubuntu 14.04 安装 JDK8  http://www.linuxidc.com/Linux/2014-09/106218.htm 

Ubuntu下安装JDK图文解析 http://www.linuxidc.com/Linux/2014-09/107291.htm 

更多SUSE相关信息见SUSE 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=3

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-09/135214.htm

赞(0) 打赏
转载请注明出处:服务器评测 » OpenSUSE下安装JDK
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏