I recently installed Java but when I open the command line and I enter:
java -version
I get back:
C:\Users\Tim>java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
But when I enter:
javac -version
I get back:
C:\Users\Tim>javac -version
'javac' is not recognized as an internal or external command,
operable program or batch file.
I added the following line to the end of my path in environment variables:
;C:\Program Files\Java\jdk1.8.0_60\bin;
I installed this version:
jdk-8u60-windows-x64.exe
I use Windows 10. I have sought out multiple sources for help but none of them seem to be working. I think I've installed the right package as the name is JDK, it is for Windows on a 64 machine and java is found, but the compiler is not. I'm trying to train on Java now, but I'm stuck here and can't go much further until I iron this out. I appreciate any help. Thank you.
You missed some steps. Go to variable environment and do the following:
System Variables:
Edit path variable adding the following:
;C:\ProgramFiles\Java\Java_version\bin
Create a new variable. Its name will be classpath and its value will be:
;C\ProgramFiles\Java\Java_Version\src.zip
User Variables :
Create a variable called path, its value will be:
C:\ProgramFiles\Java\Java_verson\bin
Create a variable called classpath , its value will be:
C\ProgramFiles\Java\Java_Version\src.zip
I had that problem.. the solution is to remove all spaces from the java path. So instead of having it located at:
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_60
move the jdk folder to,
for example: JAVA_HOME = C:\Java\jdk1.8.0_60
Then add the following line to the end of path in environment variables:
C:\Java\jdk1.8.0_60\bin;
it worked for me :)
Related
Trying to get OpenJDK 17 installed for Pufferpanel. User pi can do java -version fine however Pufferpanel gets bash: java: command not found
My /etc/profile and /etc/profile.d/java.sh have these lines:
#JAVA
export JAVA_HOME="/usr/lib/jvm/jdk-17.0.1+12"
export PATH=$JAVA_HOME/bin:$PATH
In addition JAVA_HOME="/usr/lib/jvm/jdk-17.0.1+12" is set in /etc/environment
Full permissions have been given for java.sh and the JAVA_HOME folder with chmod 777. The user pufferpanel now can run the script however the error stays the same: bash: java: command not found.
Trying some things out and found this:
pufferpanel#raspberrypi:/home/pi$ whereis java
java: /usr/share/java
Meanwhile pi gives this output:
pi#raspberrypi:~ $ whereis java
java: /usr/share/java /usr/lib/jvm/jdk-17.0.1+12/bin/java
Good news is that Java does run as the user pufferpanel:
pufferpanel#raspberrypi:/usr/lib/jvm/jdk-17.0.1+12/bin$ ./java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
OpenJDK Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)
My guess is that PATH is getting overwritten somewhere, just don't know where.
If there are easier ways to install Java that is higher than version 16 just to get Minecraft to work, please tell me!
What you are doing is fine, but you should probably create a custom.sh shell script in /etc/profile.d/
As for environment variables, like JAVA_HOME, they should go in /etc/environment
Setting the PATH in ~/.bashrc worked out, copied java.sh and pasted it in. Couldn't find ~/.bashrc at first, but this helped to figure that out.
As Pufferpanel is a different matter, I'm marking this the answer to my question which was getting Java to work as an user.
I have jdk12 and jdk8 on my computer installed. Usually jdk12 is set in the path.
To run some java programs I had set path to jdk8. Now after changing the path back to /jdk-12.0.1/bin, running java -version on cmd still returns
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
I decided to assemble my comments to an answer:
When calling java on the command line, the OS only uses the PATH environment variable to look for the command. The variable JAVA_HOME is not used here.
So you simply should examine the PATH variable: The directory C:\Program Files (x86)\Common Files\Oracle\Java\javapath is added to the PATH by the JDK installer. I would suggest to remove it, so you have better control what directories are part of the PATH.
If you have multiple Java installed, create the JAVA_HOME variable and give the JAVA path which you want to use. Use only this JAVA_HOME variable in the PATH variable.
If you wish to change the default Java, change only the JAVA_HOME variable pointing to the required JAVA.
This way, only one JAVA (which is required) will be present in PATH. Remove all other JAVA references in the PATH variable.
Also, whenever you change the JAVA_HOME value, open a new terminal (command prompt) to verify this change.
Note: If the path contains spaces, use the shortened path name. For example, C:\Progra~1\Java\jdk1.8.0_65
At the time of this post (11/19/2019), I downloaded Java JDK version 13.0.1 on my windows 10 machine. After the download, I modified the Path system variable on my machine to include this path "C:\Program Files\Java\jdk-13.0.1\bin" (without double quotes). I then modified my JAVA_HOME system variable to include this path "C:\Program Files\Java\jdk-13.0.1". However, when I type "java -version" at the command prompt, this is what I get.
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
Can someone please explain to me why my current java version from the command prompt is displaying the result above as opposed to java version 13.0.1? Thanks in advance!
Try uninstall old JDK. I don't change anything when I install new JDK and I only choose new JDK within new project.
I have actually 3 versions of JDK.
Try setting the java_home and path using Command prompt.
setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0"
setx PATH "%PATH%;%JAVA_HOME%\bin";
Note:
Once you set in command prompt, close and reopen cmd.exe for the changes to reflect.
Have a Happy programming !!! :-)
References:
https://www.codejava.net/java-core/how-to-set-environment-variables-for-java-using-command-line
Before marking it duplicate FYI I have already read How can I change the Java Runtime Version on Windows (7)? and How to set path for Jre 6 when jre 7 installed?.
I have both Java7 and Java8 in my machine. I have
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_60
PATH = ...;%JAVA_HOME%\bin;....
but I am getting
C:\>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
C:\>javac -version
javac 1.7.0_60
I want to set JRE to 1.7 too. How to do that?
You will probably have to edit your path environment variable.
If you want to check what's in your PATH environment variable in an organized fashion, run:
echo %path:;=&echo.%
Make sure the 1.8 is not on the path or if you want it there make sure it appears after 1.7.
To edit it, go to My Computer > Properties > System Properties > Advanced tab > Advanced section > Environment Variables.
Also check what is actually launched when you run java from the command line, run the following command:
where java
It will show you what windows runs when you request java.
To solve the problem, remove or change the name of java.exe and javaw.exe into System32 folder:
Prepend the System Variable's Path with JRE bin's path.
where java did work for me. I found there is another version of java associated with the SPSS (1.8.0). Uninstall SPSS and the problem solved.
The solution that worked for me was:
In "Path" variable replace "C:\ProgramData\Oracle\Java\javapath;" with %JAVA_HOME%\bin where JAVA_HOME variable was set to "C:\Program Files\Java\jdk1.7.0_60"
I've installed jdk 7 and set up the "JAVA_HOME" to this version. Then, I've installed jdk 6 and I've updated the "JAVA_HOME" to point to jdk 6. After closing and reopening the system, when typing "java -version", I got always :
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) Client VM (build 24.0-b56, mixed mode, sharing)
However, when typing
echo %JAVA_HOME%
I got :
C:\Program Files\Java\jdk1.6.0_45
I didn't understand why java -version don't display the value of "JAVA_HOME"
Java 7 puts a java.exe in c:\windows\system32. You could try to delete these exe's, but I'm not sure Windows will allow it, or restore it after a reboot.
If you want to override it, you must put %JAVA_HOME%\bin as first entry in your PATH, before c:\windows\system32.
Which java starts when you run java -version depends on the PATH env variable, not JAVA_HOME. OS will be looking for java.exe (Windows) like for any other program
if you run java on your command window, it takes java from the PATH variable. JAVA_HOME is used my maven etc...
I believe your PATH variable is pointing to JAVA version 1.7.0_40/bin directory.
According to my understanding, this is nothing to do with your JAVA_HOME environment variable. You are getting java version from C:\windows\system32\java.exe.
If you don’t want that behaviour then in system variables section put %JAVA_HOME%\bin as starting element (Of course you should have JAVA_HOME). (I thought of adding image but I dont have enough reputation to do so :( )