Setting java home variable in windows

Как прописать JAVA_HOME?

Картинка для привлечения внимание. Ноги, кафель, ну вы поняли.

Windows:

Приступим к настройке.

  1. Давим по значку рабочего стола правой кнопки мыши -> открывается окно «Система».
  2. На левой панели давим по пункту «Дополнительные параметры системы» -> открывается окно «Свойства системы»
  3. На вкладке «Дополнительно» нажимает на кнопку «Переменные среды. » -> открывается окно «Переменные среды»

Перед вами 2 списка, в верхнем списке указаны все переменные доступные только вашему пользователю, в нижнем — всей системе. В некоторых случаях может потребоваться установить разные переменные JAVA_HOME для нескольких юзеров одной системы, в этом случае для каждого юзера придется прописать свою переменную в списке «Переменные среды пользователя». Мы пойдем обычным путем и установим одинаковую переменную для всех.

  • Необходимо убедиться что переменной JAVA_HOME нет в списке, если есть, давим кнопку изменить и переходим к 6 пункту.
  • Давим кнопку «Создать. «.
  • Указываем имя переменной «JAVA_HOME», в значении переменной указываем полный путь до папки с JDK, например «C:\java\jdk1.7.0_79\».

Окно «Свойств системы» в Windows

Не будет лишним так-же указать переменную «JRE_HOME», она пригодится, например, для разработки портлетов для портала Liferay, для этого по аналогии повторите пункт 6. Как правило, JRE находится в папке с JDK, примерный путь «C:\java\jdk1.7.0_79\jre\».

После установки дистрибьютива JDK виртуальная машина «java.exe» будет доступна в консоли повсеместно. Для выполнения некоторых задач, необходимо так-же предоставить доступ к компилятору «javac.exe», для этого отредактируйте переменную Path. Добавьте в значение переменной «;» и путь до папки с компилятором, например «C:\Java\jdk1.7.0_79\bin\».

Ubuntu:

Для начала необходимо понять куда была установлена Java, выполните команды:

Результатом выполнения команды будет список установленных виртуальных машин Java:

Из этого списка нам потребуется столбик Path. Полный путь до виртуальных машин должен быть до «jre/bin/java», например в нашем случае 0-ой пункт будет иметь полный путь до машины «/usr/lib/jvm/java-8-oracle».

Для установки переменной JAVA_HOME, необходимо прописать ее в /etc/environment, используя путь до машины Java.

Изменения вступят в силу автоматически после перезагрузки, либо мы можем перегрузить переменные окружения командой:

Осталось выполнить проверку:

Если в результате команда напечатает путь до машины JAVA, значит настройка завершена успешно.

Читайте также:  Expand d i386 ntoskrnl ex c windows system32

JRE_HOME

Не будет лишним так-же указать переменную «JRE_HOME», она пригодится, например, для разработки портлетов для портала Liferay. Как правило, JRE находится в папке с JDK, т.е. значение JRE_HOME = путь до виртуальной машины + «/jre».

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

  1. Open Search and type advanced system settings
  2. In the shown options, select the View advanced system settings link
  3. Under the Advanced tab, click Environment Variables
  4. In the System variables section, click New (or User variables for single user setting)
  5. Set JAVA_HOME as the Variable name and the path to the JDK installation as the Variable value and click OK
  6. Click OK and click Apply to apply the changes

2.2. Windows 7

  1. On the Desktop, right-click My Computer and select Properties
  2. Under the Advanced tab, click Environment Variables
  3. In the System variables section, click New (or User variables for single user setting)
  4. Set JAVA_HOME as the Variable name and the path to the JDK installation as the Variable value and click OK
  5. 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

Читайте также:  Windows теряет жесткий диск

/.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 – что это такое и она нужна

Во многих статьях в интернете, документации к инструментам для разработки на 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.

Читайте также:  Office 2007 совместимость для 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.

  1. Correct – C:\Program Files\Java\jdk1.8.0_60
  2. 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

Confluence Support

Knowledge base

Products

Jira Software

Project and issue tracking

Jira Service Management

Service management and customer support

Jira Core

Manage any business project

Confluence

Bitbucket

Git code management

Resources

Documentation

Usage and admin help

Community

Answers, support, and inspiration

Suggestions and bugs

Feature suggestions and bug reports

Marketplace

Billing and licensing

Frequently asked questions

Viewport

Confluence

Versions

Setting the JAVA_HOME Variable in Windows

Installing Java for Confluence

On this page

Still need help?

The Atlassian Community is here for you.

To install Confluence manually on Windows, you will need to set an environment variable to point Confluence to the your Java installation directory.

This information is only relevant if you’re installing Confluence manually on a Windows server. If you’re using the installer, you don’t need to do this.

In most cases you should set the JRE_HOME environment variable, but if it is not set, Confluence will use JAVA_HOME.

Related pages

Set the JAVA_HOME Variable

To set the JRE_HOME or JAVA_HOME variable:

Locate your Java installation directory

If you didn’t change the path during installation, it’ll be something like C:\Program Files\Java\jdk1.8.0_65

You can also type where java at the command prompt.

In the Variable Value field, enter your JDK or JRE installation path .

If the path contains spaces, use the shortened path name. For example, C:\Progra

Note for Windows users on 64-bit systems

1 = ‘Program Files’
Progra

2 = ‘Program Files(x86)’

You’ll need to close and re-open any command windows that were open before you made these changes, as there’s no way to reload environment variables from an active command prompt. If the changes don’t take effect after reopening the command window, restart Windows.

Set the JAVA_HOME variable via the command line

If you would prefer to set the JAVA_HOME (or JRE_HOME) variable via the command line:

    Open Command Prompt (make sure you Run as administrator so you’re able to add a system environment variable).

Set the value of the environment variable to your JDK (or JRE) installation path as follows:

If the path contains spaces, use the shortened path name.

Restart Command Prompt to reload the environment variables then use the following command to check the it’s been added correctly.

You should see the path to your JDK (or JRE) installation.

Оцените статью