“java -version”在命令提示符下不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2380572/
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 -version" not working in command prompt
提问by l--''''''---------''''''''''''
I downloaded this Java JDKand installed it.
我下载了这个Java JDK并安装了它。
But when I go to the command prompt to check the version, it says it's not recognized.
但是当我去命令提示符检查版本时,它说它无法识别。
Is anyone else experiencing this issue with the latest Java?
有没有其他人在使用最新的 Java 时遇到过这个问题?
I might not have installed the right version. I need the java that works with grails
我可能没有安装正确的版本。我需要与grails一起使用的 java
C:\>java
'java' is not recognized as an internal or external command,
operable program or batch file.
C:\>java -version
'java' is not recognized as an internal or external command,
operable program or batch file.
C:\>
when i do a search on my computer for java, it does not find anything
当我在我的电脑上搜索 java 时,它没有找到任何东西
采纳答案by user2730936
Windows 2k8 R2 server- For both java [-option] or %JAVA_HOME% to work in the command line you need the following:
Windows 2k8 R2 服务器 - 要让 java [-option] 或 %JAVA_HOME% 在命令行中工作,您需要以下内容:
In Control Panel->System and Security->System->Advanced system setting->Advanced->Environment Variables->System Variables
在控制面板->系统和安全->系统->高级系统设置->高级->环境变量->系统变量
Edit the Path variable and add a ";" after the last value and add the the path to the Java bin directory: e.g.- C:\Progra~2\Java\jre6\bin\
编辑 Path 变量并添加一个“;” 在最后一个值之后并添加 Java bin 目录的路径:例如- C:\Progra~2\Java\jre6\bin\
Add the JAVA_HOME Variable with the value set to the path for the java executable: e.g.- C:\Progra~2\Java\jre6\bin\java.exe
添加 JAVA_HOME 变量,其值设置为 java 可执行文件的路径:例如- C:\Progra~2\Java\jre6\bin\java.exe
回答by JasCav
Is the -version flag not recognized, or is the "java" command not recognized? One way to test this is just to type 'java' by itself and run it and see what happens.
是 -version 标志未被识别,还是“java”命令未被识别?测试它的一种方法是单独键入“java”并运行它,看看会发生什么。
If the command is not recognized, make sure that the JDK's install path is in your windows PATH. If not, you won't be able to use any of the java executables from the command prompt. Here's another linkthat may help out.
如果无法识别该命令,请确保 JDK 的安装路径在您的 Windows PATH 中。否则,您将无法从命令提示符使用任何 java 可执行文件。 这是另一个可能有帮助的链接。
回答by Mark B
You most likely don't have java.exe in your system's PATH variable.
您很可能在系统的 PATH 变量中没有 java.exe。
回答by Melvin
You installed the JDK. Isn't java.exe part of the JRE? Do you have that installed?
您安装了 JDK。java.exe 不是 JRE 的一部分吗?你有那个安装吗?
回答by Alex Ivasyuv
For Linux:
对于 Linux:
check $PATH and $JAVA_HOME. You can configure it in /etc/environment
检查 $PATH 和 $JAVA_HOME。你可以在/etc/environment中配置它
From console you can check it like:
从控制台你可以检查它像:
$ echo $PATH
For Windows:
对于 Windows:
My Computer -> Properties -> Advanced -> Environment Variables Check there PATH.
我的电脑 -> 属性 -> 高级 -> 环境变量 检查那里的 PATH。
From console you can check it like:
从控制台你可以检查它像:
echo %PATH%
回答by Olivier Croisier
Press simultaneously the "windows" and "pause" buttons on your keyboard, this will bring up the System Preferences dialog. In the Advanced tab, find Environment Variables.
同时按下键盘上的“windows”和“pause”按钮,这将调出“系统偏好设置”对话框。在高级选项卡中,找到环境变量。
Then, in the User (upper) section, create or update the following two variables :
然后,在 User (upper) 部分,创建或更新以下两个变量:
- JAVA_HOME = where you put your JDK, eg. C:/Java/SDK
- PATH = %JAVA_HOME%/bin
- JAVA_HOME = 您放置 JDK 的位置,例如。C:/Java/SDK
- 路径 = %JAVA_HOME%/bin
Close the dialogs.
关闭对话框。
Then, in a new command-line console, try "javac -version" and see if it's detected. It's important that you use a new console, because environment variables are read only when the console is launched.
然后,在新的命令行控制台中,尝试“javac -version”并查看是否检测到它。使用新控制台很重要,因为只有在启动控制台时才会读取环境变量。
回答by John Topley
You need to manually add the path to javac.exe and java.exe to your operating system path. The Java installation program doesn't do that for you.
您需要手动将 javac.exe 和 java.exe 的路径添加到您的操作系统路径中。Java 安装程序不会为您执行此操作。
回答by Michael Borgwardt
Java is typically installed (on Windows) as C:\Program Files\Java\jdk<version>
Java 通常安装(在 Windows 上)作为 C:\Program Files\Java\jdk<version>
That installation directory has a subdirectory bin
which you need to append to your PATH environment variable via the control panel. Then, the commands like java
, javac
etc. will be available on the command line.
该安装目录有一个子目录bin
,您需要通过控制面板将其附加到 PATH 环境变量中。然后,像的命令java
,javac
等等将是可利用在命令行上。
BTW, the same is true for Grails.
顺便说一句,Grails 也是如此。
回答by álvaro González
You should have a Javaicon in Windows Control Panel. Locate the Javatab and click the Viewbutton. That will show you the path to the Java executables.
您应该在 Windows 控制面板中有一个Java图标。找到Java选项卡并单击查看按钮。这将显示 Java 可执行文件的路径。
Last but not least, make sure you have restarted the computer so changes in the PATH variable can take effect.
最后但并非最不重要的一点是,确保您已重新启动计算机,以便 PATH 变量中的更改生效。
回答by Cloud Cho
For me, it was incorrect line in the PATH
对我来说,PATH 中的行不正确
(1) Check PATH: Type "Edit System Environment Variables" on the search -> System Properties -> Advance -> Environment Variables -> System variables -> Path
(1)检查PATH:在搜索上输入“编辑系统环境变量”->系统属性->高级->环境变量->系统变量->路径
(2) On the list, mine was C:\Program Files (x86)\Common Files\Oracle\Java\javapath
so I just add \
at the end (the exe files in the javapath
folder)
(2)在列表中,我的是C:\Program Files (x86)\Common Files\Oracle\Java\javapath
所以我只是\
在最后添加(文件javapath
夹中的exe文件)
OS: Windows 10 64 bit
操作系统:Windows 10 64 位