Windows set environment variable java home

How to set JAVA_HOME environment variable on Windows 10

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.

error java command

Or Eclipse will fail to launch:

Читайте также:  Truncate function in php

Eclipse launch error no Java home found

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:

Java home directory

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:

start menu open system environment variable dialog

The System Properties dialog appears, click the button Environment Variables.

System properties dialog

Then you will see this dialog:

Environment Variables 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:

New JAVA HOME system variable

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:

Edit Path variable

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:

Edit Path variable for Java home

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:

verify java home

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.

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

Comments

Thank you for this helpful article !
With your help I managed to get rid of an annoying message poping every minute.

Thanks, Minh. I was having a fit getting jEdit to work despite Java being installed. The alternate method adding the literal path did not work. Your method with JAVA_HOME does work.

Источник

Переменная окружения 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 Variable on Windows 11

A step-by-step guide to setting up and verifying the JAVA_HOME variable on the Windows operating system to run and execute Java files.

How to Set JAVA_HOME Variable on Windows 11

While running your Java program/application, if you are getting a JAVA_HOME error. Then this may be because you have not set up the JAVA_HOME environment variable on your Windows 11. Here is a detailed guide on; how to set the JAVA_HOME variable on Windows.

JAVA_HOME is the name of an environment variable on the operating system that points to the installation directory of Java Runtime Environment or Java Development Kit. You can also check out our guide on; how to install and set up Java JDK on Windows 11.

How to Setup JAVA_HOME Variable on Windows 10

By just downloading and installing Java, Java files will not work. You have to; set up the java environment variable and JAVA_HOME variable on your Windows 11. So, the system can execute the Java code on your Windows 11 system.

To set up the JAVA_HOME variable, follow the steps mentioned below. Or, if you prefer a video tutorial, you can watch the video mentioned below.

Step 3: It will open the “System Properties window. Click on the “Advanced” tab and click the “Environment Variable” option.

Step 4: Under the “System variables“section, click the “New” button. Here, enter JAVA_HOME as a variable name and the installation directory of Java JDK under variable value. Then click on “OK” to save the changes.

Step 5: Now, go back to the “Environment Variable” window and select “Path” under the System variable. Then click on the “Edit” button.

Step 6: Here, you need to add the JAVA_HOME variable to the Path. For that, click on “New” and type %JAVA_HOME%\bin to add the new environment variable. After that, click on “OK” to save the changes.

How to Verify JAVA_HOME Variable

By following; the above steps, you can set the JAVA_HOME variable on your system. Now, to verify the JAVA_HOME environment variable, follow the below steps:

Step 1: Click the “Start” button, search for “cmd,” and open the command prompt as administrator.

Step 2: Now run the following command:

This command should print the directory of the Java JDK to which the JAVA_HOME is pointing. Or else, you will get an empty line if the JAVA_HOME variable is not configured correctly.

Step 3: Next, run the javac —version command; to check the version of the Java compiler.

If everything went fine, that means; you have successfully set the JAVA_HOME on Windows 11. Now, you are ready to run Java files on your Windows operating system.

Conclusion

That’s it; this is how you can set the JAVA_HOME variable on Windows 11. If you want to run and write Java code, you can also check out our detailed guide on; how to install and set up Eclipse IDE on Windows 11 for Java programming.

I hope this article was helpful to you. If you liked the article, share it with your friends and family. If you have some suggestions, do not hesitate to leave them in the comments section below.

Источник

Setting the JAVA_HOME Variable in Windows

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\Eclipse Adoptium\jdk-11.0.17.8-hotspot\ or C:\Program Files\Java\jdk-17.0.4.1\ You can also type where java at the command prompt.

  • Do one of the following:
    Windows 7 – Right click My Computer and select Properties >Advanced
    Windows 8 – Go to Control Panel >System >Advanced System Settings
    Windows 10 – Search for Environment Variables then select Edit the system environment variables
  • Click the Environment Variables button.
  • Under System Variables, click New.
  • In the Variable Name field, enter either:
    • JAVA_HOME if you installed the JDK (Java Development Kit)
      or
    • JRE_HOME if you installed the JRE (Java Runtime Environment)
  • In the Variable Value field, enter your JDK or JRE installation path.
  • Click OK and Apply Changes as prompted
  • 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:

    1. Open Command Prompt (make sure you Run as administrator so you’re able to add a system environment variable).
    2. Set the value of the environment variable to your JDK (or JRE) installation path as follows:
    setx /m JAVA_HOME "C:\Program Files\Java\jdk11.0.17.8"

    Источник

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