English
Ask Your Question
5

[Sticky] How do I install oracle Java?

asked 2014-12-12 06:28:53 +0000

yasharne gravatar image

updated 2017-01-13 21:43:19 +0000

mattdm gravatar image

hi i have just installed fedora 21,I have installed oracle jdk8 from its rpm pakage with no failure but when i type alternatives --config java i just see one choice which is openjdk, i tried to install oracle jdk pakage again but it says

package jdk1.8.0_20-2000:1.8.0_20-fcs.x86_64 is already installed

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
8

answered 2014-12-12 09:39:44 +0000

updated 2016-02-08 20:53:14 +0000

To extend on @vtrfny 's answer here is my ultimate guide on how to install Oracle JDK 8 once for all.

How to install Oracle JDK 8 on Fedora 21

  • Download Oracle JDK from here and install using following command.

    • Install

      rpm -ivh jdk-<version>-linux-x64.rpm
      
    • Upgrade

      rpm -Uvh jdk-<version>-linux-x64.rpm
      

This will install Oracle JDK 8 in /usr/java/jdk<version>.

  • Choose Alternatives

    • Config

      alternatives --config java
      alternatives --config javac
      alternatives --config javaws
      
    • Verify

       $ alternatives --list | grep /usr/java
       javaws  manual  /usr/java/jdk1.8.0_74/bin/javaws
       javac   manual  /usr/java/jdk1.8.0_74/bin/javac
       java    manual  /usr/java/jdk1.8.0_74/jre/bin/java
      
  • Verify Installation

    $ java -version
    java version "1.8.0_74"
    Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
    $ javac -version
    javac 1.8.0_74
    

Information below is no longer required.

Starting with version 8u40, the JDK installation is integrated with the alternatives framework and after installation, the alternatives framework is updated to reflect the binaries from the recently installed JDK. Java commands such as java, javac, javadoc, and javap can be invoked from the command line. Source - Oracle JDK Installation Instructions

  • Setup Alternatives

    su -
    alternatives --install /usr/bin/java java /usr/java/default/jre/bin/java 200000
    alternatives --install /usr/bin/javaws javaws /usr/java/default/jre/bin/javaws 200000
    alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /usr/java/default/jre/lib/amd64/libnpjp2.so 200000
    alternatives --install /usr/bin/javac javac /usr/java/default/bin/javac 200000
    alternatives --install /usr/bin/jar jar /usr/java/default/bin/jar 200000
    
  • Choose Alternatives

       su -
       alternatives --config java
       alternatives --config javaws
       alternatives --config libjavaplugin.so.x86_64
       alternatives --config javac
       alternatives --config jar
    
  • Errors

    failed to read link /usr/bin/javaws: No such file or directory`
    

For solution see this blogpost.

edit flag offensive delete link more
1

answered 2014-12-12 08:17:25 +0000

You need to add it to list of alternatives first:

alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_25/jre/bin/java 200000
edit flag offensive delete link more

Comments

thank you so much, can you explain what 200000 means? thanks

yasharne ( 2014-12-12 09:24:25 +0000 )edit

The number is priority (higher is better, so 200000 is just some random really high number).

vtrefny ( 2014-12-12 09:48:38 +0000 )edit
0

answered 2015-05-08 04:03:23 +0000

cheesiechimp gravatar image

For configuring alternatives, I follow a slightly different approach to @donniezazen's steps.

Below approach is useful for me as I frequently use other components during Java development.

sudo /usr/sbin/alternatives  \
  --install /usr/bin/java      java        /usr/java/jdk1.8.0_45/bin/java          20000 \
  --slave /usr/lib/jvm/java_home_dir java_home_dir /usr/java/jdk1.8.0_45 \
  --slave /usr/bin/javadoc     javadoc     /usr/java/jdk1.8.0_45/bin/javadoc \
  --slave /usr/bin/javaws      javaws      /usr/java/jdk1.8.0_45/bin/javaws \
  --slave ... add those you need ... keytool / orbd / servertool / rmiregistry ... etc

Full alternatives command is here

Also configure such that JAVA_HOME is switched each time alternatives is used.

sudo vim /etc/profile.d/sun-jdk.sh  

# /etc/profile.d/sun-jdk.sh
#
# Set PATH for Sun JDK

export JAVA_HOME=`realpath /etc/alternatives/java_home_dir`

PATH=$JAVA_HOME/bin:$PATH
export PATH

Don't forget to make the script executable

sudo chmod +x /etc/profile.d/sun-jdk.sh
edit flag offensive delete link more

Comments

Slightly improved "full" command here , it's easier to edit the path to fit your situation.

Quintesse ( 2015-05-19 15:47:02 +0000 )edit

@cheesiechimp I don't really understand master slave thing of alternatives. I like the idea of switching alternatives. I will look into it. Thanks.

sudhirkhanger ( 2015-05-21 15:23:44 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Use your votes!

  • Use the 30 daily voting points that you get!
  • Up-vote well framed questions that provide enough information to enable people provide answers.
  • Thank your helpers by up-voting their comments and answers. If a question you asked has been answered, accept the best answer by clicking on the checkbox on the left side of the answer.
  • Down-voting might cost you karma, but you should consider doing so for incorrect or clearly detrimental questions and answers.

Question Tools

Follow
4 followers

Stats

Asked: 2014-12-12 06:28:53 +0000

Seen: 49,150 times

Last updated: Feb 08 '16