UBUNTU and Java; JAVA_HOME no longer an issue

Posted on by Nick. 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…

Get a Trackback link

1 Trackbacks/Pingbacks

  1. Pingback: Java 1.5 su Ubuntu 9.10 | Rainbowbreeze on December 7, 2009

Comments (16)

  1. iamoogabooga on July 16, 2007 - 8:06 am

    works ;)

  2. Ali on July 18, 2007 - 3:56 am

    Great! :)

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

  4. Jedi Tiger 1.5 on August 14, 2007 - 6:38 am

    Yes, It worked!, Thank you very much.

  5. Anonymous on September 10, 2007 - 5:19 am

    It works, muchas gracias!!!

  6. aremania on February 12, 2008 - 7:31 pm

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

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

  8. Anonymous on August 12, 2008 - 4:27 pm

    You are a lifesaver!

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

  10. Nick on August 26, 2008 - 9:37 am

    hmmm. it looks good to me.

    I will have a think about it…

    anyone else?

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

  12. LordVarma on September 28, 2008 - 1:57 am

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

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

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

  15. Ihsanullah on April 27, 2009 - 4:48 pm

    (Allah de musalman ka)
    It works for me

  16. mastrobardo on August 5, 2010 - 6:35 am

    tnx a lot

Post a comment

1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165|166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184|185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|208|209|210|211|212|213| how to buy herbal soma online no prescription buying premarin buying risperdal on line chloroquine without prescription generic buying desyrel buy generic doxycycline benicar order online canada generic buying zyprexa buying bystolic pharmacy without prescription order fluoxetine pills viagra soft without prescription order cheap alesse purchasing hydrochlorothiazide pharmacy without prescription flagyl no prescription how to buy strattera online no prescription buy no prescription fluoxetineAccutane Online Doxycycline online Buy Cheap Lexapro Online No Prescription Prednisone Online Buy Accutane No Prescription