Saturday, May 9, 2015

Installing and Configuring Java in Ubuntu completely through terminal -Part 2 : Set JAVA_HOME

My previous post explained how to install java completely through terminal. After installing java you need to set the java path in your machine as a variable since various kinds of applications and servers require and request the JAVA_HOME in your machine. Therefore the path to JAVA should be correctly set.

I start this assuming that you have correctly installed java in your machine. If not have a look at part 1 post to correctly install java in your machine or in a remote server. 

To do this task through terminal, you will need vi or vim editor installed in your machine. If not do the following in the terminal.

1.First type apt-get command to install vim as following.

     sudo apt-get install vim

Give password credentials and get installed vim.

Now you can use vi commands in your terminal. 

The only thing you have to do to set the java path is editing .bashrc file and set JAVA_HOME.

2. Type the following command to open up .bashrc file.

     vi .bashrc

3. Go down to the bottom of the file and press the key "i" to ge the file editable.

4. Type following lines at the bottom of the file.

      #JAVA HOME
      JAVA_HOME=/usr/lib/jvm/java-6-oracle        
      export JAVA_HOME
      PATH=PATH=${JAVA_HOME}/bin:${PATH}
      export PATH

These lines will add JAVA_HOME variable to the system properties. 
/usr/lib/jvm/java-6-oracle is the path to JAVA in my machine. This may vary according to the version that you have installed in your machine.

Set the PATH to the bin folder of JAVA. Export both variables.


5. press Esc to go back from the edit mode of the .bashrc file

6. press :w for changes to be written. Then the changes to the file will be saved.

7. pres :q! to quit the fie.

8. Now type the following command in the terminal to verify (print) the JAVA_HOME.

echo $JAVA_HOME

 It will print JAVA_HOME.



9. Type the following command in the terminal to verify (print) the PATH.

echo $PATH

It will print PATH.


Done!

You have successfully configured the java path in your machine now.
 

No comments:

Post a Comment