Tech

20120809

How to Install OpenJDK on Ubuntu

A. To install the OpenJDK on ubuntu is very easy and one shot deal. First you need to search for the JDK version. First open a terminal and run the following command:

$ sudo apt-cache search openjdk-

This should give you some choices like:


openjdk-6-doc - OpenJDK Development Kit (JDK) documentation
openjdk-6-jdk - OpenJDK Development Kit (JDK)
openjdk-6-jre - OpenJDK Java runtime, using Hotspot JIT
and 
openjdk-7-doc - OpenJDK Development Kit (JDK) documentation
openjdk-7-jdk - OpenJDK Development Kit (JDK)
openjdk-7-jre - OpenJDK Java runtime, using Hotspot JIT

many others packages should appear. 

OR

you can just type in the following command: 

$ sudo apt-get install openjdk- 

and tab twice!

B. To install the OpenJDK now you can run the following command and similar to the one above: 

$ sudo apt-get install openjdk-6-jdk

Just follow the screen instructions and that's it. 

C. In case you installed both OpenJDK-6 and OpenJDK-7, you can simple switch between both by using this command. 

$ sudo update-alternatives --config java

Then you should see this: 
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 

I have selected 2 to set the OpenJDK-7 as the default java. 

D. In case you want to set any program java home to the non-default, in my case OpenJDK-6. You can just provide the path: /usr/lib/jvm/java-6-openjdk-i386 




No comments:

Post a Comment