RSS Feed!

Recent Posts

Recent Comments

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 »

18 Comments

  1. iamoogabooga says:

    works ;)

  2. Ali says:

    Great! :)

  3. Ali says:

    Just a bit of comment, I didn’t need to reboot my server, just open a new pUtty.

  4. Jedi Tiger 1.5 says:

    Yes, It worked!, Thank you very much.

  5. Anonymous says:

    It works, muchas gracias!!!

  6. aremania says:

    work, thanks,
    no restart, ctrl+backspace and login

  7. Anonymous says:

    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)

  8. Anonymous says:

    You are a lifesaver!

  9. Razor says:

    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.

  10. Nick says:

    hmmm. it looks good to me.

    I will have a think about it…

    anyone else?

  11. Razor says:

    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

  12. LordVarma says:

    Thnx a lot brother… worked well for me… :-)

  13. Rechner-Tester says:

    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

  14. Keilaron says:

    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.

  15. Ihsanullah says:

    (Allah de musalman ka)
    It works for me

  16. [...] 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 [...]

  17. mastrobardo says:

    tnx a lot

  18. 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.

Leave a Reply