Set env 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:

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.

Источник

How to Set JAVA_HOME for JDK & JRE: A Step-by-Step Guide

This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.

This article has been viewed 323,351 times.

Are you seeing Java errors like «JAVA_HOME is not defined correctly?» or «JAVA_HOME is set to an invalid directory?» If you’ve recently installed the Java Development Kit (JDK) or the Java Runtime Environment (JRE), you’ll need to set your JAVA_HOME variables and configure the path so applications know where to find Java. This wikiHow article will show you the easiest ways to change or set the Java home path on Windows, macOS, and Linux.

  • Before you can set JAVA_HOME, you’ll need the full path to your JDK or JRE installation.
  • Once you set the JAVA_HOME environment variable, you can run the command echo $JAVA_HOME to see the new path.
  • To set the Java home and path on Linux or macOS permanently (even after a reboot), add the environment variables to your .bashrc or .zshrc file.

Windows

Image titled Set Java Home Step 1

  • Open File Explorer, click This PC in the left panel, then navigate to C:\Program Files\Java. The directory you’re looking for should have the name of the JDK version, such as C:\Program Files\Java\jdk-19.
  • If you installed the JRE instead of the JDK, you’ll have something like C:\Program Files\Java\jre1.8.0_351 instead.
  • You can also open the command prompt and run the command wmic product where «Name like ‘%%Java%%'» get installlocation,Name . This will tell you the full path of the JDK, even if you haven’t yet set JAVA_HOME.

Image titled Set Java Home Step 2

  • Press the Windows key on your keyboard and type advanced system .
  • Click View advanced system settings in the search results.

Image titled Set Java Home Step 3

Click the Environment Variables button. You’ll see it at the bottom-right corner of the System Properties window.

Image titled Set Java Home Step 4

  • If you have multiple installations of the JDK and want to change JAVA_HOME to your new installation, select the current JAVA_HOME user variable and click Edit… instead.

Image titled Set Java Home Step 5

  • If you’re editing the current JAVA_HOME path, you’ll already have JAVA_HOME here. So, you can skip this step.
Читайте также:  Number format php округление

Image titled Set Java Home Step 6

  • If you’re adding a second path to JAVA_HOME, just type a semicolon (;) after the first path, then enter the second path.
  • If you’re replacing an old JAVA_HOME path, just delete the current path and enter the new one.

Image titled Set Java Home Step 7

Image titled Set Java Home Step 8

  • If you want other users on this PC to be able to access Java binaries from the command line, repeat this step for the «Path» variable under «System variables» as well.

Image titled Set Java Home Step 9

  • Click the New button at the top.
  • Enter the full path to the JRE or JDK with \bin at the end. For example, C:\Program Files\Java\jdk-19\bin or C:\Program Files\Java\jre1.8.0_351\bin.
  • Click OK.

Image titled Set Java Home Step 10

  • You won’t need to restart your computer for the changes to take effect, but you will need to relaunch any apps that were trying to access Java.
  • Open a new command prompt window and run the command echo %JAVA_HOME% to display the new path to JAVA_HOME.
    • Make sure this is a new command prompt window. If you still have the same window open, the command will fail because it doesn’t have the new environment variables.

    macOS

    Image titled Set Java Home Step 11

    Open a Terminal window. To open Terminal, search for Terminal in Spotlight. Or, you can open Finder, click the Go menu, select Utilities, and choose the Terminal app.

    Image titled Set Java Home Step 12

    • If you have more than one Java installation and want to see the paths to all of them, use /usr/libexec/java_home -V instead.

    Image titled Set Java Home Step 13

    Copy the path and paste it somewhere handy. Highlight the path to the Java installation you want to use as JAVA_HOME, press Cmd + V to copy it, then paste it into a sticky note or text file.

    Image titled Set Java Home Step 14

    • Type cd ~ and press Return.
    • Type open .zshrc and press Return. This should open the file in a text editor.
    • If the file is not found, type echo > .zshrc and press Return. Then, run open .zshrc again.

    Image titled Set Java Home Step 15

    • export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home
      • Replace /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home with the full path to the /Contents/Home directory of your Java installation if it’s different.

      Image titled Set Java Home Step 16

      Type source .zshrc and press ⏎ Return . Once you’ve edited your profile, this command ensures that your environment variables will be updated for the current terminal window (and any other windows you open from now on).

      Image titled Set Java Home Step 17

      • If you had any other windows open that were attempting to find Java binaries, close and reopen them.
      • Shopping for PC accessories or office supplies? Check out our coupon site for Staples discounts or our coupon site for Office Depot.

      Linux

      Image titled Set Java Home Step 18

      Image titled Set Java Home Step 19

      • readlink -f `which javac`
      • If that doesn’t work, try running update-alternatives —list java .
      • If neither of these commands works, run whereis java , which will usually result in a symbolic link like /usr/bin/java.
        • Once you get the directory, find out where it links using ls -la /bin/java .
        • If that points you to another directory, e.g., /etc/alternatives/java, run ls -la /etc/alternatives/java .
        • At that point, you should see a much longer directory, which is actually the home to the Java binaries. For example, usr/lib/jvm/java-11-openjdk-arm64/bin/java . This is the directory you want.

        Image titled Set Java Home Step 20

        • echo «export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-arm64» >> ~/.bashrc
        • echo «export PATH=$PATH:$JAVA_HOME/bin» >> ~/.bashrc

        Image titled Set Java Home Step 21

        Expert Q&A

        In Linux, you can set JAVA__HOME for all users by editing the global .bashrc, which is located at /etc/bash.bashrc. Just use echo and replace ~/.bashrc with /etc/bash.bashrc .

        You Might Also Like

        Check Your Java Version in the Windows Command Line

        Use Easy Windows CMD Commands to Check Your Java Version

        Do Division in Java

        How to Do Division in Java (Integer and Floating Point)

        Compile and Run Java Program by Notepad

        How to Compile and Run Java Programs Using Notepad++

        Compile & Run Java Program Using Command Prompt

        Calculate Percentage in Java

        Add JARs to Project Build Paths in Eclipse (Java)

        Check Null in Java

        Install Java in Ubuntu Using Terminal

        Program in Java

        Create an Executable File from Eclipse

        Update Java

        Call a Method in Java

        Print Double Quotes in Java

        Simple Steps to Type a Bunny with Your Keyboard

        Check Java Version on a Mac

        About This Article

        This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 323,351 times.

        Is this article up to date?

        Quizzes

        You Might Also Like

        Use Easy Windows CMD Commands to Check Your Java Version

        How to Do Division in Java (Integer and Floating Point)

        How to Compile and Run Java Programs Using Notepad++

        Источник

        Переменная окружения 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, где она используется и как её корректно указать.

        Источник

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