OpenSUSE 上的 Java 8 JDK 安装 - 更新替代方案

OpenSUSE 上的 Java 8 JDK 安装 - 更新替代方案

我在许多 OpenSUSE 论坛上搜索了这个问题的答案,但到目前为止我还没有找到。长话短说,当从 Oracle 安装 JDK 的 RPM 时,我收到以下信息:

> sudo zypper install jdk-8u111-linux-x64.rpm
[sudo] password for root:
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  jdk1.8.0_111

1 new package to install.
Overall download size: 158.3 MiB. Already cached: 0 B. After the operation, additional 258.5 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package jdk1.8.0_111-2000:1.8.0_111-fcs.x86_64           (1/1), 158.3 MiB (258.5 MiB unpacked)
Checking for file conflicts: ......................................................................[done]
(1/1) Installing: jdk1.8.0_111-2000:1.8.0_111-fcs.x86_64 ..........................................[done]
Additional rpm output:
Unpacking JAR files...
    tools.jar...
    plugin.jar...
    javaws.jar...
    deploy.jar...
    rt.jar...
    jsse.jar...
    charsets.jar...
    localedata.jar...
update-alternatives: using /usr/java/jdk1.8.0_111/jre/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: error: alternative ControlPanel can't be slave of javac: it is a slave of java
warning: %post(jdk1.8.0_111-2000:1.8.0_111-fcs.x86_64) scriptlet failed, exit status 2

请原谅我的冗长,我只是想让你看到的和我看到的一样。这是全新安装的 OpenSUSE Tumbleweed。

我还尝试在 OpenSUSE Leap 42.2 上全新安装它。在我第一次尝试之后,我在没有任何 Java 支持(没有 OpenJDK)的情况下重新加载,从头开始,就像我完成此安装一样。我专门按照在 OpenSUSE 上安装 Java 的指南进行操作。没有安装 Java 的、之前安装了 java OpenJDK 的、同时安装 JDK 和 JRE 的,无论出于何种原因,等等。

根据记录,Java 本身可以正常工作,但显然控制面板却不能正常工作。我尝试手动使用更新替代方案,我尝试从头开始编译,我已经重新加载,我已经从 Leap 切换到 Tumbleweed。以下是一些可能有用的其他信息:

> sudo update-alternatives --list java
/usr/java/jdk1.8.0_111/jre/bin/java
> sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/java/jdk1.8.0_111/jre/bin/java
Nothing to configure.
> java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
> javac -version
javac 1.8.0_111

我再次看到 Java 正在运行。但我仍然想了解为什么这个问题如此容易重现以及如何解决它。

答案1

执行此安装的过程比大多数人想象的要容易,令人惊讶的是,没有太多关于如何执行此操作的好的或直接的信息。上面的答案是正确的,但有些内容有点过时了。

  1. 下载Oracle JDK 1.8.0_151

    #// rpm Installation Oracle JDK 1.8.0_151
    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"  http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.rpm
    
  2. 运行安装命令

    #// installation command
    rpm -ivh jdk-8u151-linux-x64.rp
    
  3. 验证版本是否已根据您的偏好进行配置/安装

    java -version
    
  4. 使用命令行界面或编辑器设置环境变量

    #//Command line 
    export JAVA_HOME=/usr/java/jdk1.8.0_151/
    export PATH=$PATH:/usr/java/jdk1.8.0_151/bin
    
    #// set variables at the END of the file etc/profile
    sudo vim /etc/profile/
    
    #//Variables to set within the file
    JAVA_HOME=/usr/java/jdk1.8.0_151
    PATH=$Path:$HOME/bin:@JAVA_HOME/bin
    export JAVA_HOME
    export PATH
    
    #//To save / exit vim execute the following key strokes
    <ESC>
    <:>
    <x>
    

答案2

经过几个小时的努力,我终于解决了这个恼人的问题。

看来我们不能rpm -ivh jdk-8u121-linux-x64.rpm直接安装jdk,而是jdk-8u121-linux-x64.tar.gz手动下载并解压。

(JW 1/8/2017 修订) - 你实际上可以直接通过 rpm 安装,通过以下函数

   #//rpm install
   rpm -ivh jdk-8u151-linux-x64.rpm

大部分程序可以在这个网页,并且要小心你要安装的jdk版本。

以jdk-8u121 x64为例,我建议切换到根本原因,否则会有很多sudo

1.下载jdk,选择jdk-8u121-linux-x64.tar.gz

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2.cd /path/to/downloaded/java

3.tar -xzf ./jdk-7uX-linux-XX.tar.gz

4.Open JDK 默认安装在 中/usr/lib64,因此我们/usr/lib64也将 Oracle Java 移至: mv ./jdk1.8.0_121/ /usr/lib64/

5.创建一个符号链接/usr/lib64/jdk1.X.X_XX/(这对于稍后的更新很重要): ln -s -T /usr/lib64/jdk1.X.X_XX/ /usr/lib64/jdk_Oracle

6.压缩安装中涉及的 man 文件:

gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/java.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/keytool.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/orbd.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/policytool.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/rmid.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/rmiregistry.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/servertool.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/tnameserv.1)

7.准备jvm-exports目录,注意版本!

mkdir /usr/lib64/jvm-exports/jdk_Oracle
cd /usr/lib64/jvm-exports/jdk_Oracle


ln -s /usr/lib64/jdk_Oracle/jre/lib/rt.jar jaas-1.8.0_Orac.jar
ln -s jaas-1.8.0_Orac.jar jaas-1.8.0.jar
ln -s jaas-1.8.0_Orac.jar jaas.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/jce.jar jce-1.8.0_Orac.jar
ln -s jce-1.8.0_Orac.jar jce-1.8.0.jar
ln -s jce-1.8.0_Orac.jar jce.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/rt.jar jdbc-stdext-1.8.0_Orac.jar
ln -s jdbc-stdext-1.8.0_Orac.jar jdbc-stdext-1.8.0.jar
ln -s jdbc-stdext-1.8.0_Orac.jar jdbc-stdext-3.0.jar
ln -s jdbc-stdext-1.8.0_Orac.jar jdbc-stdext.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/rt.jar jndi-1.8.0_Orac.jar
ln -s jndi-1.8.0_Orac.jar jndi-1.8.0.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/rt.jar jndi-cos-1.8.0_Orac.jar
ln -s jndi-cos-1.8.0_Orac.jar jndi-cos-1.8.0.jar
ln -s jndi-cos-1.8.0_Orac.jar jndi-cos.jar
ln -s jndi-1.8.0_Orac.jar jndi.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/rt.jar jndi-ldap-1.8.0_Orac.jar
ln -s jndi-ldap-1.8.0_Orac.jar jndi-ldap-1.8.0.jar
ln -s jndi-ldap-1.8.0_Orac.jar jndi-ldap.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/rt.jar jndi-rmi-1.8.0_Orac.jar
ln -s jndi-rmi-1.8.0_Orac.jar jndi-rmi-1.8.0.jar
ln -s jndi-rmi-1.8.0_Orac.jar jndi-rmi.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/jsse.jar jsse-1.8.0_Orac.jar
ln -s jsse-1.8.0_Orac.jar jsse-1.8.0.jar
ln -s jsse-1.8.0_Orac.jar jsse.jar
ln -s /usr/lib64/jdk_Oracle/jre/lib/rt.jar sasl-1.8.0_Orac.jar
ln -s sasl-1.8.0_Orac.jar sasl-1.8.0.jar
ln -s sasl-1.8.0_Orac.jar sasl.jar


/usr/sbin/update-alternatives --install /usr/bin/java java /usr/lib64/jdk_Oracle/bin/java 3 --slave /usr/share/man/man1/java.1.gz java.1.gz /usr/lib64/jdk_Oracle/man/man1/java.1.gz --slave /usr/lib64/jvm/jre jre /usr/lib64/jdk_Oracle/jre --slave /usr/lib64/jvm-exports/jre jre_exports /usr/lib64/jvm-exports/jdk_Oracle --slave /usr/bin/keytool keytool /usr/lib64/jdk_Oracle/bin/keytool --slave /usr/share/man/man1/keytool.1.gz keytool.1.gz /usr/lib64/jdk_Oracle/man/man1/keytool.1.gz --slave /usr/bin/orbd orbd /usr/lib64/jdk_Oracle/bin/orbd --slave /usr/share/man/man1/orbd.1.gz orbd.1.gz /usr/lib64/jdk_Oracle/man/man1/orbd.1.gz --slave /usr/bin/policytool policytool /usr/lib64/jdk_Oracle/bin/policytool --slave /usr/share/man/man1/policytool.1.gz policytool.1.gz /usr/lib64/jdk_Oracle/man/man1/policytool.1.gz --slave /usr/bin/rmid rmid /usr/lib64/jdk_Oracle/bin/rmid --slave /usr/share/man/man1/rmid.1.gz rmid.1.gz /usr/lib64/jdk_Oracle/man/man1/rmid.1.gz --slave /usr/bin/rmiregistry rmiregistry /usr/lib64/jdk_Oracle/bin/rmiregistry --slave /usr/share/man/man1/rmiregistry.1.gz rmiregistry.1.gz /usr/lib64/jdk_Oracle/man/man1/rmiregistry.1.gz --slave /usr/bin/servertool servertool /usr/lib64/jdk_Oracle/bin/servertool --slave /usr/share/man/man1/servertool.1.gz servertool.1.gz /usr/lib64/jdk_Oracle/man/man1/servertool.1.gz --slave /usr/bin/tnameserv tnameserv /usr/lib64/jdk_Oracle/bin/tnameserv --slave /usr/share/man/man1/tnameserv.1.gz tnameserv.1.gz /usr/lib64/jdk_Oracle/man/man1/tnameserv.1.gz

8.压缩安装中涉及的 man 文件:

gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/appletviewer.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/apt.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/extcheck.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jar.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jarsigner.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/javac.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/javadoc.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/javah.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/javap.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jcmd.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jconsole.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jdb.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jhat.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jinfo.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jmap.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jps.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jrunscript.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jsadebugd.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jstack.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jstat.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/jstatd.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/native2ascii.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/pack200.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/rmic.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/schemagen.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/serialver.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/unpack200.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/wsgen.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/wsimport.1)
gzip $(readlink -f /usr/lib64/jdk_Oracle/man/man1/xjc.1)




/usr/sbin/update-alternatives --install /usr/bin/javac javac /usr/lib64/jdk_Oracle/bin/javac 3 \
--slave /usr/bin/appletviewer appletviewer /usr/lib64/jdk_Oracle/bin/appletviewer \
--slave /usr/share/man/man1/appletviewer.1.gz appletviewer.1.gz /usr/lib64/jdk_Oracle/man/man1/appletviewer.1.gz \
--slave /usr/bin/apt apt /usr/lib64/jdk_Oracle/bin/apt \
--slave /usr/share/man/man1/apt.1.gz apt.1.gz /usr/lib64/jdk_Oracle/man/man1/apt.1.gz \
--slave /usr/bin/extcheck extcheck /usr/lib64/jdk_Oracle/bin/extcheck \
--slave /usr/share/man/man1/extcheck.1.gz extcheck.1.gz /usr/lib64/jdk_Oracle/man/man1/extcheck.1.gz \
--slave /usr/bin/jar jar /usr/lib64/jdk_Oracle/bin/jar \
--slave /usr/share/man/man1/jar.1.gz jar.1.gz /usr/lib64/jdk_Oracle/man/man1/jar.1.gz \
--slave /usr/bin/jarsigner jarsigner /usr/lib64/jdk_Oracle/bin/jarsigner \
--slave /usr/share/man/man1/jarsigner.1.gz jarsigner.1.gz /usr/lib64/jdk_Oracle/man/man1/jarsigner.1.gz \
--slave /usr/lib64/jvm/java java_sdk /usr/lib64/jdk_Oracle \
--slave /usr/lib64/jvm-exports/java java_sdk_exports /usr/lib64/jvm-exports/jdk_Oracle \
--slave /usr/share/man/man1/javac.1.gz javac.1.gz /usr/lib64/jdk_Oracle/man/man1/javac.1.gz \
--slave /usr/bin/javadoc javadoc /usr/lib64/jdk_Oracle/bin/javadoc \
--slave /usr/share/man/man1/javadoc.1.gz javadoc.1.gz /usr/lib64/jdk_Oracle/man/man1/javadoc.1.gz \
--slave /usr/bin/javah javah /usr/lib64/jdk_Oracle/bin/javah \
--slave /usr/share/man/man1/javah.1.gz javah.1.gz /usr/lib64/jdk_Oracle/man/man1/javah.1.gz \
--slave /usr/bin/javap javap /usr/lib64/jdk_Oracle/bin/javap \
--slave /usr/share/man/man1/javap.1.gz javap.1.gz /usr/lib64/jdk_Oracle/man/man1/javap.1.gz \
--slave /usr/share/man/man1/jcmd.1.gz jcmd.1.gz /usr/lib64/jdk_Oracle/man/man1/jcmd.1.gz \
--slave /usr/bin/jconsole jconsole /usr/lib64/jdk_Oracle/bin/jconsole \
--slave /usr/share/man/man1/jconsole.1.gz jconsole.1.gz /usr/lib64/jdk_Oracle/man/man1/jconsole.1.gz \
--slave /usr/bin/jdb jdb /usr/lib64/jdk_Oracle/bin/jdb \
--slave /usr/share/man/man1/jdb.1.gz jdb.1.gz /usr/lib64/jdk_Oracle/man/man1/jdb.1.gz \
--slave /usr/bin/jhat jhat /usr/lib64/jdk_Oracle/bin/jhat \
--slave /usr/share/man/man1/jhat.1.gz jhat.1.gz /usr/lib64/jdk_Oracle/man/man1/jhat.1.gz \
--slave /usr/bin/jinfo jinfo /usr/lib64/jdk_Oracle/bin/jinfo \
--slave /usr/share/man/man1/jinfo.1.gz jinfo.1.gz /usr/lib64/jdk_Oracle/man/man1/jinfo.1.gz \
--slave /usr/bin/jmap jmap /usr/lib64/jdk_Oracle/bin/jmap \
--slave /usr/share/man/man1/jmap.1.gz jmap.1.gz /usr/lib64/jdk_Oracle/man/man1/jmap.1.gz \
--slave /usr/bin/jps jps /usr/lib64/jdk_Oracle/bin/jps \
--slave /usr/share/man/man1/jps.1.gz jps.1.gz /usr/lib64/jdk_Oracle/man/man1/jps.1.gz \
--slave /usr/bin/jrunscript jrunscript /usr/lib64/jdk_Oracle/bin/jrunscript \
--slave /usr/share/man/man1/jrunscript.1.gz jrunscript.1.gz /usr/lib64/jdk_Oracle/man/man1/jrunscript.1.gz \
--slave /usr/bin/jsadebugd jsadebugd /usr/lib64/jdk_Oracle/bin/jsadebugd \
--slave /usr/share/man/man1/jsadebugd.1.gz jsadebugd.1.gz /usr/lib64/jdk_Oracle/man/man1/jsadebugd.1.gz \
--slave /usr/bin/jstack jstack /usr/lib64/jdk_Oracle/bin/jstack \
--slave /usr/share/man/man1/jstack.1.gz jstack.1.gz /usr/lib64/jdk_Oracle/man/man1/jstack.1.gz \
--slave /usr/bin/jstat jstat /usr/lib64/jdk_Oracle/bin/jstat \
--slave /usr/share/man/man1/jstat.1.gz jstat.1.gz /usr/lib64/jdk_Oracle/man/man1/jstat.1.gz \
--slave /usr/bin/jstatd jstatd /usr/lib64/jdk_Oracle/bin/jstatd \
--slave /usr/share/man/man1/jstatd.1.gz jstatd.1.gz /usr/lib64/jdk_Oracle/man/man1/jstatd.1.gz \
--slave /usr/bin/native2ascii native2ascii /usr/lib64/jdk_Oracle/bin/native2ascii \
--slave /usr/share/man/man1/native2ascii.1.gz native2ascii.1.gz /usr/lib64/jdk_Oracle/man/man1/native2ascii.1.gz \
--slave /usr/bin/pack200 pack200 /usr/lib64/jdk_Oracle/bin/pack200 \
--slave /usr/share/man/man1/pack200.1.gz pack200.1.gz /usr/lib64/jdk_Oracle/man/man1/pack200.1.gz \
--slave /usr/bin/rmic rmic /usr/lib64/jdk_Oracle/bin/rmic \
--slave /usr/share/man/man1/rmic.1.gz rmic.1.gz /usr/lib64/jdk_Oracle/man/man1/rmic.1.gz \
--slave /usr/bin/schemagen schemagen /usr/lib64/jdk_Oracle/bin/schemagen \
--slave /usr/share/man/man1/schemagen.1.gz schemagen.1.gz /usr/lib64/jdk_Oracle/man/man1/schemagen.1.gz \
--slave /usr/bin/serialver serialver /usr/lib64/jdk_Oracle/bin/serialver \
--slave /usr/share/man/man1/serialver.1.gz serialver.1.gz /usr/lib64/jdk_Oracle/man/man1/serialver.1.gz \
--slave /usr/bin/unpack200 unpack200 /usr/lib64/jdk_Oracle/bin/unpack200 \
--slave /usr/share/man/man1/unpack200.1.gz unpack200.1.gz /usr/lib64/jdk_Oracle/man/man1/unpack200.1.gz \
--slave /usr/bin/wsgen wsgen /usr/lib64/jdk_Oracle/bin/wsgen \
--slave /usr/share/man/man1/wsgen.1.gz wsgen.1.gz /usr/lib64/jdk_Oracle/man/man1/wsgen.1.gz \
--slave /usr/bin/wsimport wsimport /usr/lib64/jdk_Oracle/bin/wsimport \
--slave /usr/share/man/man1/wsimport.1.gz wsimport.1.gz /usr/lib64/jdk_Oracle/man/man1/wsimport.1.gz \
--slave /usr/bin/xjc xjc /usr/lib64/jdk_Oracle/bin/xjc \
--slave /usr/share/man/man1/xjc.1.gz xjc.1.gz /usr/lib64/jdk_Oracle/man/man1/xjc.1.gz

9.Web浏览器插件

/usr/sbin/update-alternatives --install /usr/lib64/browser-plugins/javaplugin.so javaplugin /usr/lib64/jdk_Oracle/jre/lib/amd64/libnpjp2.so 3 --slave /usr/bin/javaws javaws /usr/lib64/jdk_Oracle/jre/bin/javaws --slave /usr/share/man/man1/javaws.1 javaws.1 /usr/lib64/jdk_Oracle/man/man1/javaws.1

10.添加Java控制面板

ln -s /usr/lib64/jdk_Oracle/jre/bin/jcontrol /usr/bin/
ln -s /usr/lib64/jdk_Oracle/jre/lib/desktop/icons/hicolor/16x16/apps/sun-jcontrol.png /usr/share/icons/hicolor/16x16/apps/
ln -s /usr/lib64/jdk_Oracle/jre/lib/desktop/icons/hicolor/48x48/apps/sun-jcontrol.png /usr/share/icons/hicolor/48x48/apps/
ln -s /usr/lib64/jdk_Oracle/jre/lib/desktop/icons/LowContrast/16x16/apps/sun-jcontrol.png /usr/share/icons/locolor/16x16/apps/
ln -s /usr/lib64/jdk_Oracle/jre/lib/desktop/icons/LowContrast/48x48/apps/sun-jcontrol.png /usr/share/icons/locolor/48x48/apps/
ln -s /usr/lib64/jdk_Oracle/jre/lib/desktop/applications/sun_java.desktop /usr/share/applications

就这样!更多详细信息openSUSE 维基

相关内容