- 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
- Как установить 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
- How to set JAVA_HOME in Windows 10
- Setting JAVA_HOME in Windows 10
- Set JAVA_HOME environment variable & update the system path
- Check JAVA_HOME configuration setup using CMD
- Related Posts
- JavaFX application could not launch due to system configuration
- How to open or run a JAR file on Windows
- What is JUCheck.exe? Is it safe?
- [email protected]
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.
Как установить 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
How to set JAVA_HOME in Windows 10
In Unix terminology, an Environment variable is a string that holds information such as drive name, pathname, filename, etc. JAVA_HOME is an environment variable which addresses to the directory where Java Runtime Environment or Java Development Kit is installed in the system. To be precise say if you have installed Java in the path C:\Program Files\Java\jdk1.8.0_121 on your computer then your Java_Home is C:\Program Files\Java\jdk1.8.0_121. Basically, JAVA_Home is simply an exemplary used by Java-based programs like Apache Tomcat and other app server tools to find where Java is placed in the system.
These third-party programs make use of the environment variables that point to the directory of JDK or JRE. In simple words, it makes easy for the programs to locate the directory executable like javac in the computer. If you are not using these third party programs, then it may not be mandatory for users to set up JAVA_Home in your system. In this article, we will explain in detail how to set JAVA_HOME as the environment variable in Windows 10.
Setting JAVA_HOME in Windows 10
Set JAVA_HOME environment variable & update the system path
Download and install Java from the official site – java.com.
After installation, Go to Start menu and type Advanced system settings.
Click on View advanced system settings from the list to open System Properties.
Go to Advanced tab and click on Environment Variables button.
In the Environment Variable window, click on New button under the System variable.
In the Edit System Variable, give the Variable name as JAVA_HOME and Variable value as the path to your JDK directory.
Click on OK.
Now go back to the Environment Variable window and select Path under the System variable.
Click on Edit button to open Edit environment variable window.
Click on New button and type %JAVA_HOME%\bin.
Click OK to apply the changes.
Check JAVA_HOME configuration setup using CMD
To test your configuration, open Command prompt.
Type echo %JAVA_HOME% and hit Enter. This should print the directory of the JDK which the JAVA_HOME is pointing. Instead, if you see a space, it means you have failed in setting up environment variable.
Next Type javac -version which should print the version of Java compiler.
If not it will print a message that the javac is not recognized as an internal or external command. This means the path variable is not set correctly.
Hope this helps!
Date: July 28, 2018 Tags: Java
Related Posts
JavaFX application could not launch due to system configuration
How to open or run a JAR file on Windows
What is JUCheck.exe? Is it safe?
[email protected]
Pavithra is a Windows enthusiast, who loves keeping abreast with the latest in the world of technology.