5

JDK 9 reached yesterday,and I downloaded the jdk-9_linux-x64_bin.tar.gz.

directory

xx@xx:/usr/lib/jvm/jdk-9$ ls

bin  conf  include  jmods  legal  lib README.html  release

It and java8 are very different. I like to configure the same as java8,

export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25  
export JRE_HOME=${JAVA_HOME}/jre  
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
export PATH=${JAVA_HOME}/bin:$PATH

But java9 has no jre. So I configured it like that (Add these in the .bashrc file)

export JAVA_HOME=/usr/lib/jvm/java-9 
export CLASSPATH=.:$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH

and run source ~/.bashrc

But java version is still no change. My operating system is Ubuntu 14.04.3.

Did i do anything wrong?

Ravi
  • 30,829
  • 42
  • 119
  • 173
dai
  • 1,025
  • 2
  • 13
  • 33

5 Answers5

1

Before you start with the setting up Java, you will need remove the OpenJDK/JRE from the system

Download jdk from oracle

then extract wit command sudo tar -xvf ....

Add the following system variables to end of /etc/profile file

JAVA_HOME=<Directory where JAVA has been extracted>/jdk1.8.0

PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH

Now reload environment using command,

. /etc/profile 

Copy-paste below lines into command prompt.

sudo update-alternatives --install "/usr/bin/java" "java" "<Directory where JAVA has been extracted>/bin/java" 1 

sudo update-alternatives --install "/usr/bin/javac" "javac" "<Directory where JAVA has been extracted>/bin/javac" 1

Tell Ubuntu that our installation i.e., jdk1.8.0_05 must be the default Java.

Use below commands to do this-

sudo update-alternatives --set java <Directory where JAVA has been extracted>/bin/java

sudo update-alternatives --set javac <Directory where JAVA has been extracted>/bin/javac

sudo update-alternatives --set javaws <Directory where JAVA has been extracted>/bin/javaws 
Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
1

To install Java 9 on Ubuntu :

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java9-installer

To configure, you need to install oracle-java9-set-default package to make Java 9 default version.

sudo apt-get install oracle-java9-set-default

Similarly, you can install Java 9 using --no-install-recommends, then Java 9 won't be set as your default version.

sudo apt-get install --no-install-recommends oracle-java9-installer
Ravi
  • 30,829
  • 42
  • 119
  • 173
1

Installation and Configuration of JDK9 is step by step given below:

Install JDK9 in Ubuntu:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java9-installer

Make it as default:

sudo apt-get install oracle-java9-set-default

Changed in .bashrc, /etc/environment and also set default using

3 sections to change java configuration.

.bashrc:

export JAVA_HOME=/usr/lib/jvm/java-9-oracle
export PATH=$JAVA_HOME/bin:$PATH

/ect/environment:

JAVA_HOME="/usr/lib/jvm/java-9-oracle"
PATH=$PATH:$JAVA_HOME/bin

Then run the following command and set

sudo update-alternatives --config java

sudo update-alternatives --config javac

Then run the command

source /etc/environment

Check in terminal:

java -version
echo $JAVA_HOME
which java
which javac

Issue#1:

Execute "source /etc/environment" in every shell where you want the variables to be updated:

$ source /etc/environment

Resource Link: https://stackoverflow.com/a/5994031

Issue#2:

Just write JAVA_HOME="/usr/lib/jvm/java-9-oracle" on your /etc/environment, without the "export"

/etc/environment is supposed to contain a set of environment variables given as key=value pairs. It is not a shell script, so you can't use shell commands such as export in it.

Resource Link:

How to properly set JAVA_HOME in /etc/environment

Issue#3:

To check if java is properly installed:

$ which java

$ which javac

You should get similar output:

/usr/bin/java

Resource Link: https://stackoverflow.com/a/23124805

Issue#4:

To remove Oracle JDK completely, run the commands below:

Completely remove criteria:

sudo apt-get remove oracle-java9-installer
sudo apt-get remove --auto-remove oracle-java9-installer
sudo apt-get purge oracle-java9-installer
sudo apt-get purge --auto-remove oracle-java9-installer

Resource Link:

https://www.howtoinstall.co/en/ubuntu/trusty/tomcat7?action=remove

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • 1
    Thank you for your reply but I have already solved it.The solution was discussed in comments, and I updated the PATH.Hope your answer can help others. – dai Oct 18 '17 at 05:49
0

Here is how I did it fully in command line:

  1. apt update
  2. apt install -y curl
  3. curl -jkL -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/9+181/jdk-9_linux-x64_bin.tar.gz -o jdk-9_linux-x64_bin.tar.gz
  4. tar xvzf jdk-9_linux-x64_bin.tar.gz -C /opt/
  5. update-alternatives --install /usr/bin/java java /opt/jdk-9/bin/java 100
  6. update-alternatives --install /usr/bin/javac javac /opt/jdk-9/bin/javac 100
  7. update-alternatives --install /usr/bin/jshell jshell /opt/jdk-9/bin/jshell 100
adenix
  • 420
  • 1
  • 4
  • 10
0

The easiest way to do this:

apt-get install python-software-properties software-properties-common
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java9-installer
apt-get install oracle-java9-set-default
petertc
  • 3,607
  • 1
  • 31
  • 36