After downloading the latest .tar file I ran tar zxvf jdk-7u45-linux-x64.tar.gz
to extract java files.
Set the path in .bashrc
file (vi ~/.bashrc
) as below;
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45/bin/java
export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_45/bin
export JDK_HOME=/usr/lib/jvm/jdk1.7.0_45
export JRE_HOME=/usr/lib/jvm/jre1.7.0_45
Now, running command java -version
or which java, java PATH still pointing to the older java version (java version "1.6.0_27"
).
I know default ubuntu takes OpenJDK path. I have to change the path as latest version as my system environment variable set in .bashrc
file.
Also, sudo update-alternatives --config java
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 manual mode
* 3 /usr/lib/jvm/jdk1.7.0_45/bin/java 1 manual mode
Press enter to keep the current choice[*], or type selection number: 3
You probably want to do
OpenJDK is probably still in the path, and Linux will use the first
java
it finds.If you don't need it, I would recommend uninstalling OpenJDK.
Ubuntu (and Debian) have an elegant way to manage libraries like the
jdk
.Using
update-alternatives
you can manage multiplejdk
libraries on the same system, choosing which one you want to use as the main one.First you have to install an alternative for the new installed jdk:
In this way you install the new
jdk
as an alternative to the original one. Then you can choose which one you wan to use:You will be asked to choose which jdk you want to use, on my system I have:
At any time you can see what alternatives you have for
java
orjavac
using the--list
option:To see more options check the
update-alternatives
man page.Running command in terminal:
from the command line to set the version of the JRE you want to use as like available version install of java : 1.6 and 1.8
See below :
and choose 1 option and set java-6 version because already current choice set in java-8.
Run
to list off all the Java installations on a machine by name and directory, and then run
to choose which JRE/JDK to use.
If you want to use different JDKs/JREs for each Java task, you can run update-alternatives to configure one java executable at a time; you can run
to see the Java commands that can be configured (java, javac, javah, javaws, etc). And then
will associate that Java task/command to a particular JDK/JRE.
You may also need to set JAVA_HOME for some applications: from this answer you can use
for JREs, or
for JDKs.
Try typing the following in your terminal.
sudo update-alternatives --config java
The output will be some choices and you can select the correct one which installed to your computer.