In this post, we will see about how to set java path in windows 10 using cmd. To set java path, you need to first understand about JAVA_HOME
and how to set JAVA_HOME in windows 10.
Let’s first understand about JAVA_HOME and then we will see how to set JAVA_HOME in windows 10.
What is JAVA_HOME?
JAVA_HOME
is environment variable which contains installation directory of Java development kit(JDK) or Java Runtime environment(JRE). This environment variable is setup at operating system level.
JAVA_HOME=C:\Program Files\Java\jdk—11.0.9 |
Why do you need JAVA_HOME?
JAVA_HOME environment variable points to directory where java is installed on your system, so many java based applications such as TOMCAT use JAVA_HOME environment variable to locate java executables.
How to set JAVA_HOME in Windows 10?
- Locate JDK on your machine.
- If you are using 64-bit java, then it will be in
C:\Program Files\Java\
- If you are using 32-bit java, then it will be in
C:\Program Files (x86)\Java\
- If you are using 64-bit java, then it will be in
- Open windows search, type
environment
and click onEdit the system environment variables
. - In System properties dialog, go to Advanced tab and click on button
Enviroment Variables
. - In System variables, click
NEW...
button to add JAVA_HOME environment variable. - Provide variable name as
JAVA_HOME
and value as Java installation directory.
Now let’s see how to set java in path environment variable in windows 10.
- In System variable window, locate
Path
and click onEdit...
. - Double click on the empty row and add
%JAVA_HOME%\bin
.
Here,%
symbol is used to locate JAVA_HOME environemt variable and\bin
provides location forjava.exe
and h=javac.exe
- Close the command prompt and launch again.
- Check java version as below:
That’s all about How to set java path in windows 10.
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.
asked Aug 27, 2015 at 5:13
0
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
answered Aug 27, 2015 at 5:31
isurujayisurujay
1,38610 silver badges15 bronze badges
3
Here are the typical steps to set JAVA_HOME on Windows 10.
- Search for Advanced System Settings in your windows Search box. Click on Advanced System Settings.
- Click on Environment variables button: Environment Variables popup will open.
- Goto system variables session, and click on New button to create new variable (HOME_PATH), then New System Variables popup will open.
- 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.
- Now you are able to see your JAVA_HOME in system variables list. (If you are not able to, try doing it again.)
- 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.
- 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
answered Dec 20, 2017 at 8:51
0
- 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
answered Jun 7, 2017 at 7:40
Navin prasadNavin prasad
5681 gold badge8 silver badges18 bronze badges
0
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.
answered Mar 24, 2016 at 10:31
theINtoytheINtoy
3,3982 gold badges37 silver badges60 bronze badges
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
answered Aug 27, 2015 at 5:21
2
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
environment variable: system variable : JAVA_HOME
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_271
add path = %JAVA_HOME%\bin
answered Nov 27, 2020 at 8:27
1
Ответы
Для добавления пути к JDK
(Java Development Kit
) в переменную среды PATH
в Windows
, следуйте этим шагам:
- Откройте «Системные настройки» в
Windows
. Это можно сделать несколькими способами, например, нажав на клавишуWindows
и искать «системные настройки» или нажав правой кнопкой мыши на значке «Этот компьютер» и выбрав «Свойства» - В меню слева выберите «Дополнительные параметры системы»
- Нажмите на кнопку «Переменные среды» в нижней части окна.
- В разделе «Системные переменные» найдите переменную
Path
и выберите «Изменить» - Нажмите на кнопку «Новый» _ и введите путь к
JDK
. Обычно это путь к папке _»bin» в установленнойJDK
, например:C:\Program Files\Java\jdk1.8.0_291\bin
- Нажмите «ОК» во всех открытых окнах, чтобы сохранить изменения.
После этого вы можете использовать команды java
и javac
в командной строке Windows
из любого места в файловой системе.
Курсы по программированию на Хекслете
Backend-разработка
Разработка серверной части сайтов и веб-приложений
Frontend-разработка
Разработка внешнего интерфейса сайтов и веб-приложений и верстка
Создание сайтов
Разработка сайтов и веб-приложений на JS, Python, Java, PHP и Ruby on Rails
Тестирование
Ручное тестирование и автоматизированное тестирование на JS, Python, Java и PHP
Аналитика данных
Сбор, анализ и интерпретация данных на Python
Интенсивные курсы
Интенсивное обучение для продолжающих
DevOps
Автоматизация настройки локального окружения и серверов, развертывания и деплоя
Веб-разработка
Разработка, верстка и деплой сайтов и веб-приложений, трудоустройство для разработчиков
Математика для программистов
Обучение разделам математики, которые будут полезны при изучении программирования
JavaScript
Разработка сайтов и веб-приложений и автоматизированное тестирование на JS
Python
Веб-разработка, автоматическое тестирование и аналитика данных на Python
Java
Веб-разработка и автоматическое тестирование на Java
PHP
Веб-разработка и автоматическое тестирование на PHP
Ruby
Разработка сайтов и веб-приложений на Ruby on Rails
Go
Курсы по веб-разработке на языке Go
HTML
Современная верстка с помощью HTML и CSS
SQL
Проектирование базы данных, выполнение SQL-запросов и изучение реляционных СУБД
Git
Система управления версиями Git, регулярные выражения и основы командой строки
Похожие вопросы
- Details
- Written by
- Last Updated on 27 April 2019 | Print Email
In this article, you will understand the details about JAVA_HOME environment variable and how to set it on Windows 10.
What is JAVA_HOME?
By convention, JAVA_HOME is the name of an environment variable on the operating system that points to the installation directory of JDK (Java Development Kit) or JRE (Java Runtime Environment) – thus the name Java Home. For example:
JAVA_HOME = c:\Program Files\Java\jdk1.8.0_201
Why is JAVA_HOME needed?
To develop Java applications, you need to update the PATH environment variable of the operating system so development tools like Eclipse, NetBeans, Tomcat… can be executed because these programs need JDK/JRE to function. So the PATH environment variable should include JAVA_HOME:
PATH = Other Paths + JAVA_HOME
Other paths are set by various programs installed in the operating system. If the PATH environment variable doesn’t contain a path to JRE/JDK, a Java-based program might not be able to run. For example, typing java in the command prompt showing this error:
'java' is not recognized as an internal or external command, operable program or batch file.
Or Eclipse will fail to launch:
How to set JAVA_HOME on Windows 10
Here are the visual steps to properly set value for the JAVA_HOME and update the PATH environment variables in order to setup Java development environment on your computer:
1. Firstly, you need to identify the Java home directory, which is typically under C:\Program Files\Java directory. Open My Computer and navigate to this directory, you will see:
Here, the home of JDK is under C:\Program Files\Java\jdk1.80_201. The version number may vary, depending on the JDK you installed.
2. Open the System Environment Variables dialog by typing environment in the search area on Start menu. Click the suggested item Edit the system environment variables:
The System Properties dialog appears, click the button Environment Variables.
Then you will see this dialog:
3.Create the JAVA_HOME environment variable by clicking the New button at the bottom. In the New System Variable form, enter the name and value as follows:
Click OK, and you will see the JAVA_HOME variable is added to the list.
4.Update the PATH system variable. In the Environment Variables dialog, select the Path variable and click Edit:
Then in the Edit environment variable dialog, double click on the empty row just below the last text line, and enter %JAVA_HOME%\bin as follows:
The percent signs tell Windows that it refers to a variable – JAVA_HOME, and the \bin specifies the location of java.exe and javac.exe programs which are used to run and compile Java programs, as well as other tools in the JDK.
Click OK button to close all the dialogs, and you’re all set. Now you can open Eclipse or NetBeans to verify. Or open a command prompt and type in javac –version, you should see:
NOTES:
You can add the path to the bin directory of Java home directly into the PATH variable. But it’s strongly recommend to follow the above steps to setup a JAVA_HOME variable because many Java programs depend on it.
When you installed a JDK, you might not need to update the system variable because the installer already did it for you.
Learn more:
- How to set environment variables for Java using command line
- How to write, compile and run a hello world Java program for beginners
- What are JVM, JRE and JDK
- How to check Java version
About the Author:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.
Add comment
PATH is an environment variable that is used by Operating System to locate the exe files (.exe) or java binaries ( java or javac command). The path once it is set, cannot be overridden. The PATH variable prevents us from having to write out the entire path to a program on the Command Line Interface every time we run it. Moreover, the path is just a variable that stores a bunch of shortcuts.
To execute java console-based programs in windows or Linux environments we have to use java and javac commands. The commands java and javac are not known to the operating system as we don’t specify where the executables reside. Hence, we need to specify the path where the executables are located. This is the reason we set the path and specify the path of the bin folder because the bin contains all binary executable files. After setting the path it can load all necessary items in the program including the compiler or interpreter itself.
Below is the procedure for setting the path for both Windows and Linux:
Setting Java Path in Windows
1. Go to the Search box and type advanced system settings in it. Now click on the View advanced system settings.
2. Select the Advanced tab and then click environment variables.
3. In the system, variables click the New button. Now in the edit system variable, type variable name as JAVA_HOME and variable path as the path where the JDK folder is saved and click on OK button Usually the path of the JDK file will be C:\Program Files\Java\jdk1.8.0_60.
4. Now in the system variables go to the path and click the edit button.
5. Click the New button.
6. Now add the following path: %JAVA_HOME%\bin
Setting Java Path in Linux
- Open the terminal and enter the following command:
sudo nano /etc/environment.
- A file will be opened and add the following command to that file:
JAVA_HOME = "YOUR_PATH".
- Replace YOUR_PATH with the JDK bin file path.
- Now restart your computer or virtual machine that you are using (or) reload the file: source /etc/environment
- You can test the path by executing
echo $JAVA_HOME
- If you get the output without any error, then you’ve set the path correctly.
- If you get any errors, try repeating the procedure again.
Last Updated :
08 Sep, 2022
Like Article
Save Article