52

I got a new laptop with Windows 10 and I want to set it up so I can use java and javac from the command line.

I have searched online but all the guides are for previous versions, and I don't want to mess around with something I don't understand.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
kilmarta
  • 629
  • 1
  • 6
  • 4

7 Answers7

94

Just set the path variable to JDK bin in environment variables.

Variable Name : PATH 
Variable Value : C:\Program Files\Java\jdk1.8.0_31\bin

But the best practice is to set JAVA_HOME and PATH as follow.

Variable Name : JAVA_HOME
Variable Value : C:\Program Files\Java\jdk1.8.0_31

Variable Name : PATH 
Variable Value : %JAVA_HOME%\bin
isurujay
  • 1,386
  • 10
  • 15
  • 15
    Do not forget to restart the terminal, i.e. the "cmd", (not the computer) through which you checked the "java -version" or wanting to run any other program using CLI – Ahmet Mar 11 '16 at 18:53
  • 2
    Since the Java folder doesn't exist on a new Windows10 installation, that is a misleading and worse than useless response. – johnrubythecat Apr 10 '16 at 04:29
  • 1
    @johnrubythecat a java 8 / windows 10 setup can be done with a jdk directory tree like what's used in this answer. – worc Sep 29 '17 at 22:18
35

Here are the typical steps to set JAVA_HOME on Windows 10.

  1. Search for Advanced System Settings in your windows Search box. Click on Advanced System Settings.
  2. Click on Environment variables button: Environment Variables popup will open.
  3. Goto system variables session, and click on New button to create new variable (HOME_PATH), then New System Variables popup will open.
  4. Give Variable Name: JAVA_HOME, and Variable value : Your Java SDK home path. Ex: C:\Program Files\java\jdk1.8.0_151 Note: It should not include \bin. Then click on OK button.
  5. Now you are able to see your JAVA_HOME in system variables list. (If you are not able to, try doing it again.)
  6. Select Path (from system variables list) and click on Edit button, A new pop will opens (Edit Environment Variables). It was introduced in windows 10.
  7. Click on New button and give %JAVA_HOME%\bin at highlighted field and click Ok button.

You can find complete tutorials on my blog :

How to set JAVA_HOME in 64 bit Windows 10 OS

10
  • Right click Computer
  • Click the properties
  • On the left pane select Advanced System Settings
  • Select Environment Variables
  • Under the System Variables, Select PATH and click edit,
    and then click new and add path as C:\Program
    Files\Java\jdk1.8.0_131\bin
    (depending on your installation path)
    and finally click ok
  • Next restart your command prompt and open it and try javac
Navin prasad
  • 558
  • 1
  • 8
  • 18
8

To find the env vars dialog in Windows 10:

Right Click Start
>>  Click Control Panel  (Or you may have System in the list)
>>  Click System
>>  Click Advanced system settings
>>  Go to the Advanced Tab
>>  Click the "Environment Variables..." button at the bottom of that dialog page.
theINtoy
  • 3,388
  • 2
  • 37
  • 60
  • Just to update my orignal answer. I have found RapidEE to be a much better way of editing/maintaining env vars in windows: https://www.rapidee.com/en/about – theINtoy Aug 11 '21 at 17:05
1

Its still the same concept, you'll need to setup path variable so that windows is aware of the java executable and u can run it from command prompt conveniently

Details from the java's own page: https://java.com/en/download/help/path.xml That article applies to: •Platform(s): Solaris SPARC, Solaris x86, Red Hat Linux, SUSE Linux, Windows 8, Windows 7, Vista, Windows XP, Windows 10

  • while it says at the top that it applies to win 10, there is no section for win 10. Is it the same as win 8? – kilmarta Aug 28 '15 at 04:35
  • Try and see if you can find the similar things in windows 10 corresponding to windows 8 that u see in the link. The underlying concept hadn't change set path to tell windows where to look at to run your commands that u dont want to have to type out the full directory of that command – whitecoffee Aug 28 '15 at 05:14
1

if you have any version problems (javac -version=15.0.1, java -version=1.8.0)
windows search : edit environment variables for your account
then delete these in your windows Environment variable: system variable: Path
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Program Files\Common Files\Oracle\Java\javapath

then if you're using java 15
environment variable: system variable : Path
add path C:\Program Files\Java\jdk-15.0.1\bin
is enough

if you're using java 8

  • create JAVA_HOME
  • environment variable: system variable : JAVA_HOME
    JAVA_HOME = C:\Program Files\Java\jdk1.8.0_271
  • environment variable: system variable : Path
    add path = %JAVA_HOME%\bin
  • tharsikan
    • 41
    • 5
    • 1
      Before I wasn't aware about this! Always leave it as it's! After a good lesson right now I'm too much aware about this! What's a silly things made me mad! It's a awesome solution & save the day. Thank you [tharsikan](https://stackoverflow.com/users/8963098/) – Śhāhēēd Mar 13 '22 at 12:12
    0

    Adding Environment Variable simplified with screenshot. Check the below URL and you should be able to do without any trouble.

    https://itsforlavanya.blogspot.com/2020/08/environment-variable-simple-7-steps-to.html

    Purushoth
    • 59
    • 4