Setting JAVA_HOME on Ubuntu 10.x

6,109

Solution 1

Try removing the export statement:

JAVA_HOME = /path/to/java
PATH = $PATH:$JAVA_HOME/bin

Then echo $JAVA_HOME in a new terminal to make sure you've got things exported correctly.

echo $JAVA_HOME

Alternatively, try this:

export JAVA_HOME=/path/to/java
export PATH=$PATH:$JAVA_HOME/bin

Solution 2

Since you're on Ubuntu, and it seems that you are using the default packages of Sun's Java for the OS, you should probably use the `update-alternatives' command. As you can see, I have 2 JVM's installed, but the Sun version is the one that gets used by default.

root@workstation:~# update-alternatives --query java
Link: java
Status: manual
Best: /usr/lib/jvm/java-6-openjdk/jre/bin/java
Value: /usr/lib/jvm/java-6-sun/jre/bin/java

Alternative: /usr/lib/jvm/java-6-openjdk/jre/bin/java
Priority: 1061
Slaves:
 java.1.gz /usr/lib/jvm/java-6-openjdk/jre/man/man1/java.1.gz

Alternative: /usr/lib/jvm/java-6-sun/jre/bin/java
Priority: 63
Slaves:
 java.1.gz /usr/lib/jvm/java-6-sun/jre/man/man1/java.1.gz

If you only have one, you don't have to worry about it. If you have more than one, and need to set it, you can use the Java-specific version of the command, `update-java-alternatives'. It's all here:

https://help.ubuntu.com/community/Java

Share:
6,109

Related videos on Youtube

kocakmstf
Author by

kocakmstf

Updated on September 17, 2022

Comments

  • kocakmstf
    kocakmstf over 1 year

    I'm trying to get the Rhodes framework installed so I can develop Android apps.

    This requires that I install the SUN JDK and add JAVA_HOME and JAVA_HOME/bin to path.

    I thought I could solve this by editing my bash.bashrc file:

    JAVA_HOME="/usr/lib/jvm/java-6-sun/jre/bin/java" export JAVA_HOME PATH=$PATH:$JAVA_HOME/bin

    This still doesn't work, because when I run:

    rake run:android

    I get a prompt in the console that says the Java bin was not found in my path.

    However, running echo $PATH gets me:

    usernamee@ubuntu:~$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/username/ruby/gems/bin:/usr/lib/jvm/java-6-sun/jre/bin/java/bin:/home/username/ruby_files/android-sdk-linux_86/tools

    What are my options here?

    Edit: If the problem is not the export statement, how can I ensure that the Sun JDK is properly installed and that I am, in fact, pointing to the correct path in bashrc?

    • Naftuli Kay
      Naftuli Kay over 13 years
      run echo $JAVA_HOME in a terminal. What does that give you? Also, lose the "export" statement, should be unnecessary and might be what's giving you the problem.
    • kocakmstf
      kocakmstf over 13 years
      username@ubuntu:~$ echo $JAVA_HOME /usr/lib/jvm/java-6-sun/jre/bin/java
  • kocakmstf
    kocakmstf over 13 years
    username@ubuntu:~$ echo $JAVA_HOME /usr/lib/jvm/java-6-sun/jre/bin/java
  • Naftuli Kay
    Naftuli Kay over 13 years
    Did you edit your .bashrc file? Did it work?
  • Naftuli Kay
    Naftuli Kay over 13 years
    Try new above edits.
  • kocakmstf
    kocakmstf over 13 years
    Same problem. I think the issue is tied to my java installation. Should I delete everything from my jvm folder, then start from scratch?
  • Naftuli Kay
    Naftuli Kay over 13 years
    How did you install Java? And you're using Sun JDK? If so, why? You should wipe your Java install if you're using Sun/Oracle/Corporate/Whatever JVM, then run sudo apt-get install openjdk-6-jdk.
  • kocakmstf
    kocakmstf over 13 years
    Why should I use the openjdk as opposed to sun?
  • Naftuli Kay
    Naftuli Kay over 13 years
    Better support, easier install. I've never had any problems or real differences in using OpenJDK and Sun, in fact I've heard that OpenJDK performs better as a server than the Sun JVM.
  • David Krider
    David Krider about 13 years
    And, now that I think about it, shouldn't this go to the "Ask Ubuntu" StackExchange site?