UBUNTU and Java; JAVA_HOME no longer an issue
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…
By Nick | 12. Jul 2007 | Java, Ubuntu | 18 Comments »

works
Great!
Just a bit of comment, I didn’t need to reboot my server, just open a new pUtty.
Yes, It worked!, Thank you very much.
It works, muchas gracias!!!
work, thanks,
no restart, ctrl+backspace and login
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)
You are a lifesaver!
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.
hmmm. it looks good to me.
I will have a think about it…
anyone else?
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
Thnx a lot brother… worked well for me…
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
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.
(Allah de musalman ka)
It works for me
[...] anche la variabile JAVA_HOME, tra i tanti modi disponibili, ho preferito usare quello descritto in questo post. Basta trovare le directories dove sono installati i runtime del Java con il [...]
tnx a lot
A actually excellent submit by you my pal. We have bookmarked this web page and can arrive back again following several days to verify for virtually any new posts that you just make.