Pages

Showing posts with label JDK. Show all posts
Showing posts with label JDK. Show all posts

Thursday, September 18, 2014

Set Java alternatives in Linux

There are several version of java which are in use. We can have different application written in different versions of java. So to use a particular version we have to set a preferable version of java which will be used by our system. We can set java alternatives using these two methods which i prefer:

1. Scan for alternatives and choose from them
2. Manually assign alternative

1. Scan for alternatives and choose from them


If you have installed two versions of java line Java 6 and Java 7. You must be having directories for these versions in your /usr/lib/jvm directory. Now to choose from alternative use following command:


#update-alternatives --config java

This will scan for available versions of java in your system and give option two choose from them:

There are 2 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/jre1.7.0/jre/bin/java 3 manual mode  
Press enter to keep the current choice[*], or type selection number: 1

Now Java 7 will be set as preferable java version.
If you are using development environment, then you have to do same thing for javac:

#update-alternatives --config javac

2. Manually assign alternative

Now, if you want to use some java version which is not installed and you have downloaded its BIN version, in that case you can manually assign java version using following cammand:

#update-alternatives --install "/usr/bin/java" "java" "/home/user/jdk1.6_37/jre/bin/java" 1
#update-alternatives --set java /home/user/jdk1.6_37/jre/bin/java

and for javac,

#update-alternatives --install "/usr/bin/java" "java" "/home/user/jdk1.6_37/bin/javac" 1
#update-alternatives --set java /home/user/jdk1.6_37/bin/javac

Thursday, September 4, 2014

Install Oracle Sun JDK in Ubuntu and set JAVA_HOME

To install JDK from Oracle use following steps:

1. Download JDK from Oracle web site:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. Extract file will be of .bin format. For example - for 64-bit system we have jdk-6u37-linux-x64.bin.

3. Put this bin file in your home directory.

4. Now need to extract this file to use Java API.

5. Extract BIN file:
  • Make BIN file executable using this command: chmod +x jdk***.bin
  • For executing use: ./jdk***.bin

6. Same named folder will be created in the same directory.

7. Now need to provide JDK path to JAVA_HOME variable in .bashrc file.

8. Edit .bashrc file in editor use following command:

          gedit .bashrc

9. Now put this code in your .bashrc file:

           export JAVA_HOME=/home/jdk***
           export PATH=$JAVA_HOME/bin:$PATH

10. Save file.

11. To refresh your bash settings write this command and hit enter:

            bash

12. To verify configured JDK path use this command:

            which java

This will display your configured path i.e. /home/jdk***/bin/java