Installing Java in Ubuntu

In last December Oracle retired the "Operating System Distributor License for Java" (JDL). This means that Canonical repositories will not have the Sun-Java-JDK packages in the future (I mean it is not available even now). But the OpenJDK is available in the Ubuntu repositories so the alternative is to use Ubuntu software center to install OpenJDK or manually install JDK (people who need Sun Java) from official Oracle web site (tar.gz files are still available there). OpenJDK until end of 2011 has been the Open Source alternative of Java. But as Oracle says they themselves will be using OpenJDK as the basis for there future releases (starting from Version 7), OpenJDK became the official implementation of Java.
Installing OpenJDK in Ubuntu

Open a new terminal and type following command 

#sudo apt-get install openjdk-7-jdk

And..... That's it! :) 

I will now show you how to install Oracle java (Sun Java) in Ubuntu 11.10. 

Installing Sun Java (Sun-Java-JDK) in Ubuntu 11.10


Add following PPA repository
#sudo add-apt-repository ppa:ferramroberto/java
#sudo apt-get update

Then install Java using apt-get command
#sudo apt-get install sun-java6-jdk sun-java6-plugin

Second and the hard way is to install manually without apt-get. To do that first download the latest tar.gz packages.
Then extract it to usr/lib/ by using following commands.
 #tar -xvf jdk-7u5-linux-i586.tar.gz
Note: Use sudo mv command to move the extracted folder into /usr/lib/ directory
 
If your system has more than one version of Java, then you have to configure which one to use by default.
In order to do that, you have to run update-alternatives command.
Now run following commands in the terminal. 
#sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1 
#sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1 
#sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1 
#sudo update-alternatives --config java
 
When you see an output as follows select the number of the jdk7 (for example number is 3 in here)
There are 3 choices for the alternative java (providing /usr/bin/java). 
Selection Path Priority Status 
————————————————————
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
3 /usr/lib/jvm/jdk1.7.0/jre/bin/java 3 manual mode
Press enter to keep the current choice[*], or type selection number:3
update-alternatives: using /usr/lib/jvm/jdk1.7.0/jre/bin/java to provide /usr/bin/java (java) in manual mode.
That's it.

You must check the java version to ensure whether installation is successful. To check;
  1. Close the current terminal
  2. Open a new terminal and type java -version
  3. Similar output as follows should appear
java version “1.7.0”
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode) 

Then repeat the above for

#sudo update-alternatives --config javac
#sudo update-alternatives --config javaws

Good luck!

Comments

Popular Posts