I have installed java with the command:
sudo apt install openkdk-17-jdk
Now I installed gradle, but can’t use it, I have received error:
ERROR: JAVA_HOME is set to an invalid directory: /usr/bin/java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
- Need to say I have set the variable on my own since the JAVA_HOME wasn’t set.
I have tried all the options:
export JAVA_HOME=$(readlink -f $(which java))
(/usr/lib/jvm/java-17-openjdk-amd64/bin/java)export JAVA_HOME=$(which java)
(/usr/bin/java)export JAVA_HOME=/usr/share/java
all options from the whereis java
:
java: /usr/bin/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz
- /usr/bin/java – not a directory
- /etc/java – contains a
security
folder and it all - /usr/share/java – doesn’t contains a
java
:
ls /usr/share/java/java*
/usr/share/java/java-atk-wrapper.jar /usr/share/java/java_defaults.mk /usr/share/java/javaewah-1.1.7.jar /usr/share/java/javaewah.jar
2
Answers
Using
export JAVA_HOME=/usr/share/java
will point to the bin folder. This is just a symbolic link to the actual installation folder.You should make it if you update it to
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
.Note you should use the root folder.
In Ubuntu, Java is commonly installed in the
/usr/lib/jvm/
directory.To check Java Version:
java -version