bash Java:找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48708287/
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
Java: command not found
提问by rsp
I have installed jdk on my mac, ran /usr/libexec/java_home
and found the path to java to be this: /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
我已经在我的 mac 上安装了 jdk,运行/usr/libexec/java_home
并发现 java 的路径是这样的:/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
I added this line to my ~/.bashrc
file:
我将此行添加到我的~/.bashrc
文件中:
export PATH=$PATH:/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home
I still get this error message:
我仍然收到此错误消息:
java: command not found
java:找不到命令
Can anyone help? I have been trying Stack Overflow solutions for hours now.
任何人都可以帮忙吗?我已经尝试了几个小时的 Stack Overflow 解决方案。
Thanks!
谢谢!
回答by Arnav Borborah
You have set your PATH
to the wrong variable. Java
is inside a bin
folder, which you have to append to your current path. The correct command would be:
您已将您PATH
的变量设置为错误。Java
位于bin
文件夹内,您必须将其附加到当前路径。正确的命令是:
export PATH=$PATH:/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin
回答by Elliott Frisch
While it is sufficient to add the "bin" folder to your PATH, doing so will leave you unable to run several desirable Java standard tools (like maven, ant, sbt, scala and groovy). Instead, first set a JAVA_HOME
and then add that with "bin" to your PATH. Like,
虽然将“bin”文件夹添加到您的 PATH 中就足够了,但这样做会使您无法运行几个理想的 Java 标准工具(如 maven、ant、sbt、scala 和 groovy)。相反,首先设置 a JAVA_HOME
,然后将其与“bin”一起添加到您的 PATH 中。喜欢,
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home"
export PATH="$PATH:$JAVA_HOME/bin"