Sunday, June 20, 2010

Set Environment variables - PATH, CLASSPATH, JAVA_HOME, ANT_HOME in Ubuntu

Setting Environment variables in Ubuntu can be tricky. It comes with OpenOffice which requires OpenJDK, so the path for java is set to that of OpenJDK. The command

$ java -version

works but uses the OpenJDK. Once you have installed Sun JDK the location of the JDK should be "/usr/lib/jvm/java-6-sun-1.6.0.20" depending upon the version you have installed. Once you have installed it you may want to update the PATH, CLASSPATH variables and create environment variables like JAVA_HOME, ANT_HOME, etc.

The location to set up the environment variables in Ubuntu is /home/Your_User_Name/.bashrc. You will need to make entries like:

JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.20
ANT_HOME=/home/harkiran/javaTools/apache-ant-1.8.1
PATH=$PATH:$ORACLE_HOME/bin:$JAVA_HOME/bin:$ANT_HOME/bin
CLASSPATH=.:/usr/lib/jvm/java-6-sun-1.6.0.20/lib
export JAVA_HOME
export ANT_HOME
export CLASSPATH
export PATH

The separator to use in Linux between PATH is ":" (colon). Windows uses ";" (semi colon).

Once you have set this up you will also need to create symbolic links in the "/etc/alternatives" directory. You will need administrative privileges to do so.

$ ln -s /usr/lib/jvm/java-6-sun-1.6.0.20/bin/java /etc/alternatives/java
$ ln -s /usr/lib/jvm/java-6-sun-1.6.0.20/bin/javac /etc/alternatives/javac

Once done you can check using the commands java -version, javac -version, ant to check all is working and has been set up properly.

6 comments:

sandeep kumar said...

For Setting Environment Variables JAVA_HOME, PATH and CLASSPATH in Java in Windows refer below link

http://www.a2ztechguide.com/2011/10/setting-environment-variables-javahome.html

Amit Kumar said...

Helpful. Thanks.

Anonymous said...

Helpful for Beginners,

Keep it up!

Anonymous said...

magnificent post, very informative. I ponder why the
opposite experts of this sector don't notice this. You should proceed your writing.
I am sure, you have a great readers' base already!

my web-site: Does Vydox really work

hitesh kumar said...

Set Path and Classpath in Java

path is set for use java tool in your java program like java, javac, javap. javac are used for compile the code.
Classpath are used for use predefined class in your program for example use scanner class in your program for this you need to set classpath.

hitesh kumar said...

Set Path and Classpath in Java

path is set for use java tool in your java program like java, javac, javap. javac are used for compile the code.
Classpath are used for use predefined class in your program for example use scanner class in your program for this you need to set classpath.

Post a Comment