how to set JAVA_HOME environment variable in windows
To set JAVA_HOME on Windows, first locate the JDK installation path (e.g., C:\Program Files\Java\jdk-17), then create a system environment variable named JAVA_HOME with that path. Next, update the PATH variable by adding %JAVA\_HOME%\bin, and verify the setup using java -version and javac -version in Command Prompt. Ensure no typos exist and always use the JDK, not JRE.

Setting the JAVA_HOME environment variable on Windows is straightforward once you know where to look. The key is pointing it to the correct Java installation directory and making sure the system recognizes it. Here’s how to do it properly.

Find Your Java Installation Path
Before setting JAVA_HOME, you need to know where Java is installed. By default, it's usually in a folder like C:\Program Files\Java\jdk-17 or similar (version may vary).
If you're not sure, here’s how to locate it:
- Open the folder
C:\Program Files\Java\and check for the latest JDK version installed. - If you installed Java using an installer, it likely created a folder named something like
jdk-17.0.3orjdk1.8.0_301. - You can also search your system using File Explorer for "jdk" if you're unsure.
Take note of this path—you'll use it shortly.

Set JAVA_HOME via System Properties
Once you have the correct path, you can set JAVA_HOME through the Environment Variables settings:
- Right-click on This PC or Computer on the desktop or in File Explorer.
- Click on Properties, then go to Advanced system settings.
- In the System Properties window, click on the Environment Variables button.
- Under System variables, click New (not Edit unless JAVA_HOME already exists).
- Enter:
- Variable name:
JAVA_HOME - Variable value: the full path to your JDK root folder (e.g.,
C:\Program Files\Java\jdk-17)
- Variable name:
Make sure not to include any extra characters like quotes or a trailing backslash.

Update the PATH Variable
Setting JAVA_HOME alone won’t make Java commands work from the command line—you still need to add it to your PATH:
- Still in Environment Variables, find the Path variable under System variables and click Edit.
- Click New and type
%JAVA_HOME%\bin - Alternatively, you can paste the full path like
C:\Program Files\Java\jdk-17\bin, but using%JAVA_HOME%makes future updates easier.
Click OK through all the windows to save your changes.
Verify It Works
After setting everything up, open a new Command Prompt window and run:
java -version javac -version
If both return version numbers without errors, you're good.
If not:
- Double-check the JAVA_HOME path—no typos.
- Make sure you added
\binto the PATH. - Restart the terminal after changes, as environment variables don’t update in already open windows.
A common mistake is pointing JAVA_HOME to the JRE instead of the JDK, especially if both are installed. Stick with the JDK folder.
That’s about it. Once it's working, you probably won’t need to touch it again unless you upgrade Java versions.
The above is the detailed content of how to set JAVA_HOME environment variable in windows. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Windows could not complete the installation [FIXED]
Aug 25, 2025 am 03:34 AM
IfWindowsinstallationfailsorgetsstuck,trythesesteps:1.Disconnectexternaldevices.2.BootintoSafeMode.3.RepairsystemfilesviaCommandPromptusingsfcandDISM.4.ClearTPMandresetBIOS.5.PerformacleaninstallusingabootableUSB.
How to fix 'The credentials provided are not sufficient to access this printer' in Windows?
Aug 25, 2025 am 09:59 AM
Updateorre-enterprintercredentialsbyremovingstoredpasswordsandinputtingcorrectonesusingtheformatHOSTNAME\UsernameorDOMAIN\Username.2.OnthehostPC,enablefileandprintersharing,adjustsharingsettings,andsetthenetworkaccessmodeltoClassicorGuestonlyinLocalS
Fresh Guide: Fix Windows Printer Problems and Spooler Issues
Aug 29, 2025 am 08:12 AM
IfyourWindowsprinterisn'tworking,trythesesteps:1.RestartthePrintSpoolerservice.2.Runthebuilt-inPrinterTroubleshooter.3.Reinstalltheprinterdriver.4.Manuallyclearstuckprintjobs.5.UseCommandPrompttoresetprintingcomponents.
What is a pass key? How to create it? OEE Exchange's pass key tutorial ((APP/Web)
Aug 29, 2025 pm 03:54 PM
What is Pass Key Pass Key is a new type of authentication technology that allows users to access their accounts without manually entering their password when logging into a website or application. Through the pass key, users can complete identity authentication using fingerprint recognition, facial scanning or device unlocking methods (such as PIN code). This technology is based on the encryption key pair mechanism, providing efficient and secure protection capabilities, and effectively resisting cyber threats such as phishing attacks. Advantages of Pass Key 1. Password-free login, which is more convenient to operate: use fingerprints, faces and other biometric methods to log in directly to the account, so as to save the hassle of repeatedly entering passwords and avoid login failures caused by entering the wrong password. 2. Stronger security: Pass keys follow technical standards formulated by the FIDO Alliance and W3C, and use asymmetric encryption algorithms to replace traditional secrets.
How to use virtual private networks (VPN) on Windows
Aug 26, 2025 am 07:20 AM
TosetupanduseaVPNonWindows,firstopenSettings>Network&Internet>VPNandclickAddaVPNconnection;1.SetVPNprovidertoWindows(built-in);2.Enterarecognizableconnectionname;3.Inputtheservernameoraddressprovided;4.SelectthecorrectVPNtype(e.g.,IKEv2,L2T
How to turn off advertising ID in Windows
Aug 27, 2025 am 06:03 AM
OpenSettingsviatheStartmenu,thengotoPrivacy&security(orPrivacyonWindows10).2.ClickGeneralintheleftmenuandlocatetheadvertisingIDoption.3.Toggleoff"LetappsuseadvertisingIDtomakeadsmoreinterestingtoyoubasedonyourappactivity"todisableit.Dis
'Windows can't find one of the files in this theme' [Fixed]
Aug 28, 2025 am 06:44 AM
First, confirm whether the theme file is complete. 1. Enter the corresponding theme folder of C:\Users\YourName\AppData\Local\Microsoft\Windows\Themes\; 2. Check whether the .theme file exists; 3. Confirm whether the referenced picture is in the Backgrounds subfolder; 4. Verify whether the referenced .msstyles file actually exists; if any file is missing, you need to download the theme package and install it correctly to solve the problem.
How to find the classic Control Panel items in Windows
Aug 26, 2025 am 07:12 AM
TheclassicControlPanelinWindows10and11canbeaccessedviaStartmenusearch,Runcommand(control),FileExplorer,orright-clickingtheStartbutton.2.ControlPaneloffersthreeviews:Category,Largeicons,andSmallicons,withiconviewsbeingfastestforlocatingspecifictools.3


