UBUNTU and Java; JAVA_HOME no longer an issue
July 12, 2007 . Posted in ubuntu.
One of the things that has always taken my by surprise was the fact that once you install a JDK on your linux box you still have to manually set the JAVA_HOME environment variable.
Eventually you'd find out that by adding a line to your .bashrc all your problems are gone and when issuing an $ echo $JAVA_HOME everything would be okay.
The problem is though, that this setting is not picked up from X (graphical environment, e.g. Gnome) and when creating a launcher that needs this JAVA_HOME variable you'd find that the application won't start. I had this issue when creating a java launcher for IntelliJ Idea 7.0
Ubuntu comes to the rescue! In your /etc folder there is a environment file. Edit this file and add your JAVA_HOME variable, restart and ta da it magically works!
Here are the steps:
$ sudo gedit /etc/environment
In the editor not add the following line at the top:
JAVA_HOME="/usr/lib/jvm/java-1.5.0-sun"
Make sure that you replace java-1.5.0-sun with a valid location (this will work if you have jdk 5 installed).
Save and close! Reboot and let me know if it worked!
Cheers…
1 Trackbacks/Pingbacks
- Pingback: Java 1.5 su Ubuntu 9.10 | Rainbowbreeze on December 7, 2009

iamoogabooga on July 16, 2007 - 8:06 am
works
Ali on July 18, 2007 - 3:56 am
Great!
Ali on July 18, 2007 - 4:00 am
Just a bit of comment, I didn’t need to reboot my server, just open a new pUtty.
Jedi Tiger 1.5 on August 14, 2007 - 6:38 am
Yes, It worked!, Thank you very much.
Anonymous on September 10, 2007 - 5:19 am
It works, muchas gracias!!!
aremania on February 12, 2008 - 7:31 pm
work, thanks,
no restart, ctrl+backspace and login
Anonymous on April 16, 2008 - 1:56 am
A BIG COMMENT: To load changes like enviroment variables or a shell like things (like JAVA_HOME=…..) only do a:
> source enviroment
or source /etc/bashrc
or source over the archive that load or view the changes did it
that’s all…
(login again is the same thing because the process of login load varaible stuff)
Anonymous on August 12, 2008 - 4:27 pm
You are a lifesaver!
Razor on August 26, 2008 - 9:15 am
hmm… it doesn’t works.. i still launching from terminal with ‘idea.sh’ command. and this is annoying me..
this is my .bashrc file(according to JAVA):
export IDEA_HOME=”/home/razor/programs/idea-8243/bin/”
export JDK_HOME=”/home/razor/programs/jdk1.6.0_10/”
export JAVA_HOME=”/home/razor/programs/jdk1.6.0_10″
export PATH=”$PATH:$IDEA_HOME”
this is my environment file:
JAVA_HOME=”/home/razor/programs/jdk1.6.0_10″
please tell me what is wrong.
thank u.
Nick on August 26, 2008 - 9:37 am
hmmm. it looks good to me.
I will have a think about it…
anyone else?
Razor on August 29, 2008 - 6:10 pm
but the best solution of this problem is to add one line in the idea.sh script and erase all ‘if’ cycles at the top of the file where IDEA checks for JDK present
this is the magic line:
IDEA_JDK=$JAVA_HOME
LordVarma on September 28, 2008 - 1:57 am
Thnx a lot brother… worked well for me…
Rechner-Tester on December 8, 2008 - 1:26 am
Looking in my (Ubuntu 8.10) /usr/lib/jvm gives me java-6-sun-1.6.0.10 and a java-6-sun, with the last one linking to the first one. So maybe it’s better setting JAVA_HOME to the link, so an (minor) javaupdate won’t break the path.
Greetings
Keilaron on December 18, 2008 - 9:08 am
a) This is not an Ubuntu-specific feature.
b) You should use gksudo instead of sudo for launching programs with GUIs
c) You don’t have to reboot for this to take effect, only log out.
Ihsanullah on April 27, 2009 - 4:48 pm
(Allah de musalman ka)
It works for me
mastrobardo on August 5, 2010 - 6:35 am
tnx a lot