错误:JAVA_HOME 设置为无效目录:/usr/lib/jvm/java-8-oracle/jre/bin/java 当我在终端中运行 gradle 命令时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44427124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:10:15  来源:igfitidea点击:

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

javalinuxubuntugradlegradlew

提问by Ashok

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

我在 Ubuntu 16.04 中工作。我需要安装 gradle 并且当我使用 sudo apt list --installed 命令检查时安装了 gradle 但是当我使用 gradle -version 命令时它显示以下错误,JAVA_HOME 设置为无效目录:/usr/lib/jvm/ java-8-oracle/jre/bin/java

In sudo vim /etc/environment file,

在 sudo vim /etc/environment 文件中,

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.

谢谢。

回答by MarcoZen

On a 64bit openSuse 64 42.1 box;

在 64 位 openSuse 64 42.1 机器上;

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.

是工作并允许java模拟器运行的路径。

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

所以我认为我们必须手动浏览我们的文件系统并查看选择什么路径。

回答by asatsi

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"

我看到了不匹配。在您的环境文件中,JAVA_HOME 设置为“/usr/lib/jvm/java-8-openjdk-amd64/”,并且您提到您得到的错误与 JAVA_HOME 相关为“/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.

如果你的JAVA真的安装在/usr/lib/jvm/java-8-oracle目录下,那么你需要确保JAVA_HOME设置在那个目录下。而且您的 PATH 也在其中反映了 $JAVA_HOME/bin 。

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

我通常将 Oracle JDK/JRE 单独安装在一个单独的目录中,例如 /usr/local/jdk1.8.0 等。

回答by Lakshan Mamalgaha

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

从文件中检查 jvm 安装文件夹,例如:/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"

然后在终端运行 sudo nano /etc/environment 并添加行 JAVA_HOME="/usr/lib/jvm/java-12-oracle"

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

然后打开终端并运行 export JAVA_HOME="/usr/lib/jvm/java-12-oracle"