Ashok
Ashok

Reputation: 129

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

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.

Upvotes: 6

Views: 44391

Answers (4)

Qazi Fahim Farhan
Qazi Fahim Farhan

Reputation: 2176

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

Upvotes: 2

Lakshan Mamalgaha
Lakshan Mamalgaha

Reputation: 333

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"

Upvotes: 0

MarcoZen
MarcoZen

Reputation: 1663

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.

Upvotes: 12

asatsi
asatsi

Reputation: 472

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.

Upvotes: 0

Related Questions