1

I'm running Linux Mint Quiana. I want to run Android Studio and this requires me Java. Since i needed NetBeans i decided to install NetBeans with Java 8 bundle from oracle's website. I tried for days to set the JAVA_HOME environment variable but without success. After countless tries and webpages of solutions read. I tried the following:

  1. export JAVA_HOME=/usr/local/jdk1.8.0_20 (The location where JAva seems to be installed)
  2. JAVA_HOME=/usr/local/jdk1.8.0_20 - without the export part and queried echo $JAVA_HOME from another terminal window but it still shows up nothing at all.
  3. I tried to modify /etc/environment and add the above line but without any success. And i also tried to edit /etc/profile but still nothing worked. (by without success i mean that the variable didn't get set)

I really don't know what's up with this thing but it seems very complicated for what it should be a simple command in the shell.

When i type :

  1. update-alternatives --query java I get nothing
  2. java -version I get:

    The program 'java' can be found in the following packages:

    • default-jre
    • gcj-4.8-jre-headless
    • openjdk-7-jre-headless
    • gcj-4.6-jre-headless
    • openjdk-6-jre-headless Try: sudo apt-get install Which seems stupid to me since i can compile stuff with netbeans and this means that JDK is installed properly somewhere
  3. which java tells me nothing at all

I hope this is enough info to solve my issue.

1
  • 1
    What shell are you using? Commented Sep 11, 2014 at 23:16

3 Answers 3

1
  • Variable definitions in one terminal window are not in the scope of other terminal windows. To define a variable in all terminal windows you need to add it to a shell configuration file. Typically this will be ~/.bashrc, Bash being the default shell in most distros. You can add a line like export JAVA_HOME=/some/path in there to make the JAVA_HOME variable available to all shells and scripts run in those shells. (It's only available in shells opened after saving ~/.bashrc; if you want it to be available in an already opened terminal simply run exec "$SHELL" to restart your shell.
  • which java looks for an executable called java in the colon-separated paths contained in the PATH variable, no matter what the value of JAVA_HOME is.
  • JAVA_HOME is used by Java applications, not by the shell or the terminal. Oracle describes it as:

    An environment variable used to trigger the 'java' found in your PATH to use a different JDK image. Unfortunately, not all 'java' startup scripts obey this env variable. It's also used by many java tool startup scripts to determine what 'java' to run, bypassing the 'java' found in the PATH setting. Setting this variable during a JDK build is a bad idea, don't do it.

  • The hint about java being available in several packages means the directory of the java executable (most likely /usr/local/jdk1.8.0_20/bin in your case) is not in the PATH variable, and can be installed from the distro packages listed. You'll need to add the directory to the PATH variable like export PATH="$PATH"':/usr/local/jdk1.8.0_20/bin' in a shell startup file like above.

Does that clarify things?

3
  • 1
    I understand what you said. I followed your steps and now after a reboot when i do `echo $JAVA_HOME i do get the right path but when i try to launch android studio, i get the same error. What am i doing wrong?
    – Edeph
    Commented Sep 13, 2014 at 14:45
  • Android Studio probably needs to be configured separately. After checking the AS configuration documentation and searching for the error message you're getting you may want to add a question here with the specific error message, how you configured it, and other relevant information.
    – l0b0
    Commented Sep 13, 2014 at 15:04
  • It just states that it needs java(jdk) to start running which i can confirm since i had it installed previously on the same OS but for some reason now i can't get JAVA_HOME to work properly. I added it in my PATH variable but i don't know what else should i do. Also which java tells me nothing...
    – Edeph
    Commented Sep 13, 2014 at 15:07
0

Rather than using the Java version provided with NetBeans on Oracle's website, after digging around some more, i managed to find this answer that solved the issue in no time.

0

Unbelievable, I had to reboot my Windows 7 for my environment variable to take effect. Usually just reopening the terminal would do it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .