For certain programs, I needed to install Sun/ Oracle JDK on my machine. My default JDKs were different versions of IcedTea that would not suffice for what I needed to do (To setup IcedTea check my previous post). In this post, we would see how to install Sun/ Oracle JDK on Ubuntu
My way of checking it was to list contents links to java through the following command..
> sudo update-alternatives --list java
I also verified the contents of the /usr/lib/jvm folder to make sure I had not missed configuring a previously installed JDK.
> ls /usr/lib/jvm
As you can see, I don't see a Sun JDK installed, and I need to start from the beginning.
First step was to go to Oracle site for downloading the latest JDK (http://www.oracle.com/technetwork/java/javase/overview/index.html). Follow the links to the latest version and download it to your local machine.
Next, I copied the downloaded JDK installation file from my Downloads folder to my local folder ~/Work/Servers/jdk , where I created the following script in a shell file called install-jdk1.8.sh.
#!/bin/sh
tar -xvf jdk-8*
sudo mkdir /usr/lib/jvm
sudo mv ./jdk1.8* /usr/lib/jvm/jdk1.8.0-oracle
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0-oracle/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0-oracle/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0-oracle/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
Here is a syntax coloured screenshot of the script.
Next we make this script executable, and execute it.
> chmod a+x *.sh
>./install-jdk1.8.sh
Once the script has run, we can test the java version to confirm everything got setup correctly..
> java -version
If you see everything setup correctly, its great. If you still see an older version of JDK, use the update-alternatives command to set it up correctly by following these steps. Also, many softwares require an explicit JAVA_HOME to be set to execute correctly. This post on setting JAVA_HOME, shows how I have set it up on my machine.
Search This Blog
Showing posts with label update alternatives. Show all posts
Showing posts with label update alternatives. Show all posts
Thursday, July 9, 2015
Saturday, February 16, 2013
Fixing the Java version on Ubuntu
If you are like me, you have multiple versions of java installed on your machine. There was an initial version that shipped with Ubuntu, followed by the Sun JDK and if you have other applications installed then additional versions as well.
I ran into a similar issue on my machine when I had the right version of Java compiler being referenced but the compiled application was not running as it was picking the wrong version of Java run time.
$ javac -version
javac 1.7.0_07
$ java -version
java version "1.6.0_27"
Here is the screenshot...
I was baffled and an initial attempt at adding JAVA_HOME to .bashrc did not produce the desired results.
Finally, I learnt the right way was to update using update-alternatives in Ubuntu
Typing the following command on the terminal window lists the current version as well as the alternatives.
$ sudo update-alternatives --config java
I selected the option 2, as I needed to execute the compiled classes using Sun JDK.
Checking the java -version confirmed that the correct java had been selected.
There we go.... nicely done!
I ran into a similar issue on my machine when I had the right version of Java compiler being referenced but the compiled application was not running as it was picking the wrong version of Java run time.
$ javac -version
javac 1.7.0_07
$ java -version
java version "1.6.0_27"
Here is the screenshot...
I was baffled and an initial attempt at adding JAVA_HOME to .bashrc did not produce the desired results.
Finally, I learnt the right way was to update using update-alternatives in Ubuntu
Typing the following command on the terminal window lists the current version as well as the alternatives.
$ sudo update-alternatives --config java
I selected the option 2, as I needed to execute the compiled classes using Sun JDK.
Checking the java -version confirmed that the correct java had been selected.
There we go.... nicely done!
Subscribe to:
Posts (Atom)