Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal
Asked Answered
E

4

6

I am working in Ubuntu 16.04. I need to install gradle and the gradle is installed when i checked with sudo apt list --installed command but when i use gradle -version command it shows the following error, JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java

In sudo vim /etc/environment file,

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
http_proxy="http://username:password@IP:port no/"
https_proxy="https://IP:port no/"
ftp_proxy="ftp://IP:port no/"

I don't know where i made mistakes. Please help me.

Thanks.

Expiate answered 8/6, 2017 at 5:12 Comment(1)
try setting the path till bin directory only, no further /usr/lib/jvm/java-8-oracle/jre/bin/Seldan
M
12

On a 64bit openSuse 64 42.1 box;

readlink -f $(which java)

provided;

/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/bin/java

But;

export JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-openjdk

is the path that worked and allowed java emulator to run.

So i think we have to manually browse our file system and see what path to choose.

Mildew answered 13/1, 2018 at 16:53 Comment(1)
Working on DebianDeacon
P
2

Today I faced this problem. I am using the default java that comes with your linux distro (so in my case, linux mint).

$ whereis java

This command gave me

java: /usr/bin/java /usr/share/java

So, I opened /user/bin. There was a link to Java. I right clicked it and selected follow original link. This lead me to /usr/lib/jvm/java-11-openjdk-amd64/bin/java. So now that I know where this java is, I opened my .bashrc file, and edited the JAVA_HOME. So for my case,

## My Custom variables
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

This solved the problem.

Now if you are using some other java (say you downloaded from oracle and extracted the zip file ...), then you have to add that location. So for example, if your java is in /home/user/.sdkman/candidates/java/current, then

export JAVA_HOME=/home/user/.sdkman/candidates/java/current
export PATH=$JAVA_HOME/bin:$PATH
Petras answered 22/2, 2021 at 12:38 Comment(1)
I was installing hadoop using hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/… I completed all the steps until editing the JAVA_HOME variable in hadoop-env.sh file. to locate the actual path of the java I followed the same procedure as you did, but while executing ./hadoop command I am getting error that ERROR: JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java does not exist.Southeastwardly
H
0

I see a mismatch. In your enviornment file the JAVA_HOME is set to "/usr/lib/jvm/java-8-openjdk-amd64/" and your mentioned that the error that you got relates to the JAVA_HOME as "/usr/lib/jvm/java-8-oracle/jre/bin/java"

If you JAVA is really installed in /usr/lib/jvm/java-8-oracle directory, then you need to ensure that the JAVA_HOME is set to that directory. And also your PATH reflects $JAVA_HOME/bin in it.

I typically install Oracle JDK/JRE separately in a separate directory such as /usr/local/jdk1.8.0 etc.

Helpful answered 8/6, 2017 at 5:46 Comment(11)
now i have setted the PATH as you said as java -8- oracle but still getting same error as invalid directory "/usr/lib/jvm/java-8-oracle/jre/bin/java"Expiate
On your command path you should see the same JAVA_HOME and PATH. For that you can run "echo $JAVA_HOME" and "echo $PATH" on the command prompt.Helpful
i used "echo$JAVA_HOME" and i can see the path as /usr/lib/jvm/java-8-oracle/jre/bin/javaExpiate
That is wrong. Your JAVA_HOME should be only till /usr/lib/jvm/java-8-oracleHelpful
i setted upto /usr/lib/jvm/java-8-oracle in env file but it shows /usr/lib/jvm/java-8-oracle/jre/bin/java in terminal. what should i do please help me.Expiate
Please try to relogin to the machine and check the JAVA_HOME is set correctly or not. Or else set it manually for now and try to execute your command.Helpful
Now, when I run sudo gradle command in my source path it will run and after this giving sudo ./gradlew assemble will give the following line as, Downloading services.gradle.org/distributions/gradle3.1.bin.zip After this, it throws exception error.Expiate
I guess your original question is resolved now. This looks like some other issue.Helpful
Yes that was resolved. Now when i run ./gradlew assemble command it is trying to download something like this,Expiate
Now when i run sudo ./gradlew assemble command in source path it trying to download something like this, Downloading services.gradle.org/distributions/gradle-3.1-bin.zip Exception in thread "main" java.net.Connect Exception: Connection timed out (Connection timed out)Expiate
Is the machine connected and able to ping/connect to the gradle server?Helpful
M
0

check the jvm installtion folder from Files eg : /usr/lib/jvm/java-12-oracle

then in terminal run sudo nano /etc/environment and add the line JAVA_HOME="/usr/lib/jvm/java-12-oracle"

Then open terminal and run export JAVA_HOME="/usr/lib/jvm/java-12-oracle"

Maidy answered 19/8, 2019 at 5:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.