- Как установить JAVA_HOME в Windows 10
- Настройка JAVA_HOME в Windows 10
- Установите переменную среды JAVA_HOME и обновите системный путь
- Проверьте настройки конфигурации JAVA_HOME, используя CMD
- Переменная окружения JAVA_HOME – что это такое и она нужна
- Что такое JAVA_HOME
- Какие программы используют JAVA_HOME
- Ошибки, связанные с JAVA_HOME
- Как установить переменную окружения JAVA_HOME в Windows
- Резюме
- How to set JAVA_HOME on Windows 10?
- 1. Advanced System Settings
- 2. Environment Variables
- 3. Add JAVA_HOME
- 4. Update PATH
- Set JAVA_HOME on Windows 7, 8, 10, Mac OS X, Linux
- Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:
- 1. Overview
- 2. Windows
- 2.1. Windows 10 and 8
- 2.2. Windows 7
- 3. Mac OS X
- 3.1. Single User – Mac OS X 10.5 or Newer
- 3.2. Single User – Mac OS X Older Versions
- 3.3. Global Setting
- 4. Linux
- 4.1 Single User
- 4.2 Global Setting
- 5. Conclusion
- itavero / set_java_home.bat
Как установить JAVA_HOME в Windows 10
В терминологии Unix переменная окружения – это строка, содержащая такую информацию, как имя диска, имя пути, имя файла и т. Д. JAVA_HOME – это переменная среды, которая обращается к каталогу, где находится среда выполнения Java или Java Development Kit. установлен в системе. Точнее сказать, если вы установили Java по пути C: \ Program Files \ Java \ jdk1.8.0_121 на своем компьютере, то ваш Java_Home будет C: \ Program Files \ Java \ jdk1.8.0_121 . По сути, JAVA_Home – это просто пример, используемый программами на основе Java, такими как Apache Tomcat и другими инструментами сервера приложений, для определения местоположения Java в системе.
Эти сторонние программы используют переменные окружения, которые указывают на каталог JDK или JRE. Проще говоря, это позволяет программам легко находить исполняемый файл каталога, такой как javac, на компьютере. Если вы не используете эти сторонние программы, пользователям может быть необязательно устанавливать JAVA_Home в вашей системе. В этой статье мы подробно объясним, как установить JAVA_HOME в качестве переменной среды в Windows 10.
Настройка JAVA_HOME в Windows 10
Установите переменную среды JAVA_HOME и обновите системный путь
Загрузите и установите Java с официального сайта – java.com .
После установки перейдите в меню Пуск и введите Дополнительные параметры системы.
Нажмите Просмотреть дополнительные настройки системы в списке, чтобы открыть Свойства системы.
Перейдите на вкладку Дополнительно и нажмите кнопку Переменная среды .
В окне «Переменная среды» нажмите кнопку Создать под системной переменной.
В системной переменной Изменить укажите имя переменной в виде JAVA_HOME и значение переменной в качестве пути к каталогу JDK.
Нажмите ОК .
Теперь вернитесь в окно переменной среды и выберите путь в системной переменной.
Нажмите кнопку Изменить , чтобы открыть окно Изменить переменную среды.
Нажмите кнопку «Создать» и введите % JAVA_HOME% \ bin .
Нажмите ОК , чтобы применить изменения.
Проверьте настройки конфигурации JAVA_HOME, используя CMD
Чтобы проверить свою конфигурацию, откройте Командную строку .
Введите echo% JAVA_HOME% и нажмите Enter. Это должно напечатать каталог JDK, на который указывает JAVA_HOME. Вместо этого, если вы видите пробел, это означает, что вы не смогли настроить переменную среды.
Далее введите javac -version , который должен печатать версию компилятора Java.
Если нет, то будет напечатано сообщение о том, что javac не распознается как внутренняя или внешняя команда. Это означает, что переменная пути установлена неправильно.
Переменная окружения JAVA_HOME – что это такое и она нужна
Во многих статьях в интернете, документации к инструментам для разработки на Java и в книгах зачастую упоминается JAVA_HOME. Что же такое JAVA_HOME?
Что такое JAVA_HOME
JAVA_HOME это переменная окружения, указывающая на директорию с установленным JDK (Java Development Kit, комплект разработчика Java). JAVA_HOME это соглашение, используемое во многих программах из экосистемы Java.
Какие программы используют JAVA_HOME
- Intellij IDEA, Eclipse, NetBeans
- Apache Maven, Apache Ant, Gradle
- Apache Tomcat
- Jenkins
Некоторые игры, написанные на Java (например, Minecraft), тоже могут требовать установленной переменной JAVA_HOME.
Ошибки, связанные с JAVA_HOME
Если переменная окружения JAVA_HOME не определена, некоторые программы могут выдавать следующие ошибки:
- Переменная среды java_home не определена
- Cannot determine a valid Java Home
- JAVA_HOME is set to an invalid directory
- JAVA_HOME is not defined correctly
- JAVA_HOME environment variable is not set
- JAVA_HOME command not found
- JAVA_HOME not found in your environment
- JAVA_HOME does not point to the JDK
При появлении таких ошибок просто установите переменную JAVA_HOME
Как установить переменную окружения JAVA_HOME в Windows
Сперва вам нужно установить JDK или JRE.
- Установите JDK, если вы занимаетесь разработкой программ на Java
- Установите JRE, если вам нужно только запустить прикладную программу на Java
После установки JDK либо JRE запишите путь установки, он понадобится.
Теперь щёлкните правой кнопкой на «Мой компьютер» → «Свойства» → «Дополнительные параметры системы» → «Переменные среды…». В разделе «Системные переменные» нажмите кнопку «Создать…» и укажите следующие данные:
Имя переменной | JAVA_HOME |
Значение переменной | Путь к директории JDK / JRE, например: C:\Java\jdk-11.0.6 |
Сохраните изменения, кликнув «OK». Теперь выберите в списке переменную окружения Path и нажмите «Изменить…». В конце списка добавьте строчку со значением «%JAVA_HOME%\bin«
Для проверки откройте консоль (Win+R, cmd) и укажите последовательно укажите две команды:
Если вы правильно установили JDK/JRE и правильно установили переменные окружения, вы увидите вывод наподобие этого:
Это будет служить результатом того, что переменная JAVA_HOME установлена правильно и Java работает из командной строки.
Резюме
В данной статье мы рассказали вам, что являет собой переменная окружения JAVA_HOME, где она используется и как её корректно указать.
How to set JAVA_HOME on Windows 10?
This tutorial shows you how to set a JAVA_HOME system variable on Windows 10.
1. Advanced System Settings
Type advanced system settings in the search box (beside the Windows start button), clicks View advanced system settings .
2. Environment Variables
Select Advance tab, clicks Environment Variables
3. Add JAVA_HOME
In System variables, clicks New. button to add a new JAVA_HOME variable and point it to the JDK installed folder.
- Correct – C:\Program Files\Java\jdk1.8.0_60
- Wrong – C:\Program Files\Java\jdk1.8.0_60\bin
4. Update PATH
In System variables, find PATH , clicks edit. button :
4.1 In old version of Windows, it will prompt you below dialog box to edit the values directly, append this %JAVA_HOME%\bin; to the end of the line.
4.2 In latest Windows 10, it will prompt you below dialog box, clicks on New button, and add this %JAVA_HOME%\bin
Set JAVA_HOME on Windows 7, 8, 10, Mac OS X, Linux
Last modified: January 18, 2020
Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:
If you have a few years of experience in the Java ecosystem, and you’re interested in sharing that experience with the community (and getting paid for your work of course), have a look at the «Write for Us» page. Cheers, Eugen
1. Overview
In this quick article, we’ll take a look at how to set the JAVA_HOME variable on Windows, Mac OS X, and Linux.
2. Windows
2.1. Windows 10 and 8
- Open Search and type advanced system settings
- In the shown options, select the View advanced system settings link
- Under the Advanced tab, click Environment Variables
- In the System variables section, click New (or User variables for single user setting)
- Set JAVA_HOME as the Variable name and the path to the JDK installation as the Variable value and click OK
- Click OK and click Apply to apply the changes
2.2. Windows 7
- On the Desktop, right-click My Computer and select Properties
- Under the Advanced tab, click Environment Variables
- In the System variables section, click New (or User variables for single user setting)
- Set JAVA_HOME as the Variable name and the path to the JDK installation as the Variable value and click OK
- Click OK and click Apply to apply the changes
Open Command Prompt and check the value of the JAVA_HOME variable:
The result should be the path to the JDK installation:
3. Mac OS X
3.1. Single User – Mac OS X 10.5 or Newer
From OS X 10.5, Apple introduced a command line tool (/usr/libexec/java_home) which dynamically finds the top Java version specified in Java Preferences for the current user.
/.bash_profile in any text editor and add:
Save and close the file.
Open a Terminal and run the source command to apply the changes:
Now we can check the value of the JAVA_HOME variable:
The result should be the path to the JDK installation:
3.2. Single User – Mac OS X Older Versions
For older versions of OS X, we have to set the exact path to the JDK installation:
/.bash_profile in any editor and add:
Save and close the file.
Open a Terminal and run the source command to apply the changes:
Now we can check the value of the JAVA_HOME variable:
The result should be the path to the JDK installation:
3.3. Global Setting
To set JAVA_HOME globally for all users, the steps are the same as for single user, but the file /etc/profile is used.
4. Linux
We’re going to manipulate the PATH here, of course – so, if you haven’t done that before, here are the detailed instructions on how to do it.
4.1 Single User
To set JAVA_HOME in Linux for a single user, we can use /etc/profile or /etc/environment (preferred for system-wide setting) or
/.bashrc (user-specific setting).
/.bashrc in any text editor and add:
Save and close the file.
Run the source command to load the variable:
Now we can check the value of the JAVA_HOME variable:
The result should be the path to the JDK installation:
4.2 Global Setting
To set JAVA_HOME in Linux for all users, we can use /etc/profile or /etc/environment (preferred).
Open /etc/environment in any text editor and add:
Please note that /etc/environment is not a script, but a list of assignment expressions (that is why export is not used). This file is read at the time of login.
To set JAVA_HOME using /etc/profile, open the file and add:
Run the source command to load the variable:
Now we can check the value of the JAVA_HOME variable:
The result should be the path to the JDK installation:
5. Conclusion
In this article, we have covered ways to set the JAVA_HOME environment variable on Windows, Mac OS X, and Linux.
itavero / set_java_home.bat
@ echo off |
setlocal |
:: Check if JAVA_HOME is already defined |
IF DEFINED JAVA_HOME (exit /b 0) |
:: Get the JDK version from the registry |
set KEY = » HKLM\SOFTWARE\JavaSoft\Java Development Kit « |
set VALUE = CurrentVersion |
reg query %KEY% /v %VALUE% 2 > nul || ( |
echo JDK not installed |
exit /b 1 |
) |
set JDK_VERSION = |
for /f » tokens=2,* » %%a in (‘reg query %KEY% /v %VALUE% ^ | findstr %VALUE% ‘) do ( |
set JDK_VERSION = %%b |
) |
echo JDK VERSION: %JDK_VERSION% |
:: Get the JDK path |
set KEY = » HKLM\SOFTWARE\JavaSoft\Java Development Kit\ %JDK_VERSION% « |
set VALUE = JavaHome |
reg query %KEY% /v %VALUE% 2 > nul || ( |
echo JavaHome not defined |
exit /b 1 |
) |
set JAVAHOME = |
for /f » tokens=2,* » %%a in (‘reg query %KEY% /v %VALUE% ^ | findstr %VALUE% ‘) do ( |
set JAVAHOME = %%b |
) |
setx -m JAVA_HOME » %JAVAHOME% « |
endlocal |
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.