Set your java jre environment variables

How to set environment variables for Java on your System? : Help Center

How to set Environment variables for Java JDK on your machine?

If you want to execute Java programs, you need to install Java Development Kit(JDK) or Java Runtime Environment(JRE) and include the Java Executable location to the Path Environment Variable. Modern Java installers do this automatically.

How to check if Java is already installed and the Path variable has been set?

You can manually check if Path variable has been set once the installation is complete by following this simple method:

Читайте также:  Значок лупы в поиске css

1. Open Command Prompt(Windows) or Terminal(Mac/Linux) window.

2. Enter `java -version` and press Enter.

If this command returns a version number, Java is installed and the Path environment has been set. Otherwise, an error message will be shown and you might need to reinstall Java or set the Path variable as given below.

Note: You may either set the User-level Path variable or the System-wide Path variable. If the System-wide Path variable is set, you won’t have to do the same for other User Accounts on the machine.

What are Environment Variables — Path, JAVA_HOME, and JRE_HOME?

JAVA_HOME — This variable points to the base directory of the JDK installation in your system. This is the folder which contains the ‘bin’ and ‘lib’ folders for Java.

JRE_HOME — This variable points to the base directory of the JRE installation in your system.

Path — The Path Environment variable helps the system to determine search path for commands. When a command is executed, the system will search in these locations for an executable file with the name of the command. Therefore, if we need to run Java programs from anywhere in the System, we need to add the «Java binary folder location» to the Path variable.

Note: Path variable will be automatically set by the Java Installer.

Finding Java Installation location

For Windows:

Generally, t he java_installation_base_folder location is C:\Program Files\Java\jdk

For 64 bit machines, t he java_installation_base_folder location is C:\Program Files (x86)\Java\jdk or the above one.

For Linux:

For Linux, you might be using either OpenJDK or Oracle JDK. You can use the whereis java command to find java executable location on your Linux machine.

For OpenJDK, The java_installation_base_folder location is similar to /usr/lib/jvm/openjdk/jdk

For Oracle JDK, The java_installation_base_folder location is similar to /usr/lib/jvm/java-8-oracle/

For Mac:

You can use /usr/libexec/java_home command to find java installation folder on your Mac.

Note: There might be slight changes in your installation location according to the version of Java installed and your OS version. That’s why it is recommended to check the java installation location before setting the Path variable.

Setting the System Environment Variables

For Windows:

After getting the installation location using the where command,

1. Open Command prompt(CMD) program with Administrator privileges.

2. Enter the following command with your java base directory location and press Enter key.

setx /m JAVA_HOME "" setx /m JDK_HOME "" setx /m JRE_HOME "\jre"

Check setx /? for more help.

For Java 8 on Windows 10, we have found that the java installation location is «C:\Program Files\Java\jdk1.8.0_144»

Therefore the format of the setx command would be,

setx /m JAVA_HOME "C:\Program Files\Java\jdk1.8.0_144" setx /m JDK_HOME "C:\Program Files\Java\jdk1.8.0_144" setx /m JRE_HOME "C:\Program Files\Java\jdk1.8.0_144\jre"

For Mac/Linux:

After getting the installation location using the whereis or locate command,

1. Open Terminal window and type the following command to open the .profile file in nano editor

This will open the .profile file in the terminal window.

2. Scroll down to the end of the file and add the following line at the end.

export JAVA_HOME= export JDK_HOME= export JRE_HOME=/jre
export JAVA_HOME=/usr/java/jdk1.5.0_07 export JDK_HOME=/usr/java/jdk1.5.0_07 export JRE_HOME=/usr/java/jdk1.5.0_07/jre

3. Press Ctrl+O to write it to the file and confirm the changes.

Note: For Mac, you may need to enable locate command by executing the following command in Terminal.

sudolaunchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

Here’s another detailed article from java.com on setting up the Environment variables for Java in Windows/Mac/Linux — How do I set or change the PATH system variable?

Modified on: Fri, 29 Mar, 2019 at 1:56 PM

Did you find it helpful? Yes No

Источник

How to Setup, Configure JAVA_HOME and JRE_HOME Environment Variables on Windows?

In order to run Java application you need to have first installed Java on your Mac or Windows laptop or desktop.

It’s absolutely required to complete Java setup right way for your production & development applications. If you are a first time Java user then first step is to go to official Oracle website and download JDK.

Below detailed steps will help also if you have below questions:

  • How to fix JAVA_HOME error while starting Tomcat Server?
  • Why i’m getting jre_home is not defined correctly tomcat error?
  • How to set jre_home environment variable?
  • jre_home on windows
  • Difference between java_home vs jre_home
  • How to set jre_home via command line?

In this tutorial we will discuss how to install Java, setup JRE_HOME & JAVA_HOME environment variables on Windows platform only. For Mac and Linux, I’ll publish another tutorial with all detailed steps later.

Let’s get started

Step-1

Configure JAVA_HOME / JRE_HOME Environment Variables

  • Go to official Oracle site and Download JDK binary
  • Click on Java Download
  • Accept License Agreement
  • Download binary next to Windows x64

Step-2

  • Double click on .exe file and it will install JDK and JRE both on your Windows Laptop/Desktop
  • By default it will install JDK and JRE at location: C:\Program Files\Java folder

Step-3

  • Now minimize all windows and you will see Desktop icon (check this screenshot)
  • Right click on it
  • Click on Properties
  • Click on Advanced System Settings link as you in above diagram

Step-4

Step-5

  • New Pop-up Window will appear
  • Click on New…
  • Enter JAVA_HOME as variable name and C:\Program Files\Java\jdk1.8.0_121 as Value
  • Enter JRE_HOME as variable name and C:\Program Files\Java\jre1.8.0_121 as Value
  • Click OK button
  • Exit System Properties window

At this time, you are all set.

How to verify?

How to verify if JAVA_HOME and JRE_HOME environment variables setup correctly or not?

  • Just open command prompt
  • Type java -version
  • It will print installed Java details as shown below

That’s it. Let me know if you face any issue installing Java on your laptop. Make sure to update Java version number as per your installation in above steps. Happy coding and happy open sourcing.

What is a difference Between JRE and JDK?

Ideally JRE provides runtime environment for your application. While running your development or production environment, you just need JRE.

On other end, while you are developing Java application , JDK provides more debugging and development functionalities which wont part of JRE.

If you liked this article, then please share it on social media. Have a question or suggestion? Please leave a comment to start the discussion.

Источник

How To Set Java, JRE and JDK Home Path and Environment Variables On Windows?

How To Set Java, JRE and JDK Home Path and Environment Variables On Windows?

Java is a very popular programming language which provides a different component in order to run, develop Java applications. JRE or Java Runtime Environment is used to run Java application. JDK or Java Development Kit is used to develop Java applications. In this tutorial, we will learn how to set up Java, JRE, and JDK operating system path variables in order to work properly.

Locate JRE or JDK Path

Before starting the configuration we have to locate the JRE or JDK path. JRE or JDK generally installed on the Program Files or Program Files(x86) directory under the Java directory like below.

Locate JRE or JDK Path

and under the Java directory the JDK is residing.

Locate JRE or JDK Path

Set Java HOME_PATH Environment Variable

Now we have learned the path of the Java, JRE or JDK installation. We can set this path as Java HOME_PATH environment variable. We will open the computer properties with by running sysdm.cpl in the Run menu like below. We can also open it from the File Explorer -> Computer -> Right Click.

Open System Properties

In the system properties, we will navigate to the Advanced tab which provides the Environment Variables button like below.

Open Environment Variables

Below we can see the environment variables menu where we will create the JAVA_HOME system variable and set the path accordingly. We click to the New in order to create a new system variable.

Create New System Variable

Here we will set the Variable Name as JAVA_HOME and the Variable Value the path or Java, JRE or JDK which is C:\Program Files\Java\jdk-12 in this example. Then we will click OK.

Set System Variable Name and Value

Set JAVA Executable Path

If we want to run java.exe or similar executables provided by JRE or JDK we have to add the path of Java in the Path variable like below. We select the system variable named Path and click to the Edit .

Edit Path System Variable

Here we click to New which will add a new line to the existing values.

Here we will set the bin folder path which is C:\Program Files\Java\jdk-12\bin in this example.

Add Path System Variable

Then we will click OK and OK in the environment variables screen which will save and activated new path configuration.

Check Java Is Working

We can check the new path configuration simply opening a new command line interface MS-DOS. Then just type java -version which will execute java.exe with the -version option. We can see the current java binary version by running it.

3 thoughts on “How To Set Java, JRE and JDK Home Path and Environment Variables On Windows?”

What is the point in setting the JAVA_HOME to the path to the jdk install folder path if you then edit the Path variable and add the full path to the jdk bin folder? Shouldn’t you make use of the JAVA_HOME variable and add %JAVA_HOME%\bin to the Path instead. Reply

Источник

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

Источник

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