Setting up enviroment variables in Windows 10 to use java and javac
Asked Answered
H

7

55

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.

Hetaerism answered 27/8, 2015 at 5:13 Comment(0)
W
96

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
Washin answered 27/8, 2015 at 5:31 Comment(3)
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 CLIColossae
Since the Java folder doesn't exist on a new Windows10 installation, that is a misleading and worse than useless response.Destroy
@Destroy a java 8 / windows 10 setup can be done with a jdk directory tree like what's used in this answer.Peggy
C
40

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

Cease answered 20/12, 2017 at 8:51 Comment(0)
F
12
  • 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
Framing answered 7/6, 2017 at 7:40 Comment(0)
A
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.
Argentine answered 24/3, 2016 at 10:31 Comment(1)
Just to update my orignal answer. I have found RapidEE to be a much better way of editing/maintaining env vars in windows: rapidee.com/en/aboutArgentine
F
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

Ferule answered 27/8, 2015 at 5:21 Comment(2)
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?Hetaerism
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 commandFerule
N
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
  • Note answered 27/11, 2020 at 8:27 Comment(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 tharsikanLecture
    H
    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

    Hidrosis answered 25/8, 2020 at 13:8 Comment(0)

    © 2022 - 2024 — McMap. All rights reserved.