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-" 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:

export JAVA_HOME
export ANT_HOME
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- /etc/alternatives/java
$ ln -s /usr/lib/jvm/java-6-sun- /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.


sandeep kumar said...

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

Amit Kumar said...

Helpful. Thanks.

linuxicle 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

Post a Comment