- Setting up the environment in Java
- A. Windows operating systems
- B. Linux Operating System
- C. MacOS Operating System
- How To Set Java, JRE and JDK Home Path and Environment Variables On Windows?
- Locate JRE or JDK Path
- Set Java HOME_PATH Environment Variable
- Set JAVA Executable Path
- Check Java Is Working
- 3 thoughts on “How To Set Java, JRE and JDK Home Path and Environment Variables On Windows?”
- Переменная окружения JAVA_HOME
- Что такое JAVA_HOME
- Какие программы используют JAVA_HOME
- Ошибки, связанные с JAVA_HOME
- Как установить переменную окружения JAVA_HOME в Windows
- Резюме
Setting up the environment in Java
Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, etc. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. The latest version is Java 19. Below are the environment settings for both Linux and Windows. JVM, JRE, and JDK three are all platform-dependent because the configuration of each Operating System is different. But, Java is platform-independent. Few things must be clear before setting up the environment which can better be perceived from the below image provided as follows:
- JDK(Java Development Kit): JDK is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger.
- JRE(Java Runtime Environment): JRE contains the parts of the Java libraries required to run Java programs and is intended for end-users. JRE can be viewed as a subset of JDK.
- JVM: JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides a runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms.
Now let us discuss the steps for setting up a Java environment with visual aids. Let’s use the Windows operating system to illustrate visual aids.
Steps: Here we will be proposing steps for three different operating systems as listed:
A. Windows operating systems
The steps for setting the environment in the Windows operating system are as follows:
Step 1: Java8 JDK is available at Download Java 8. Click the first link for Windows(32-bit) and the last link for Windows(64-bit) as highlighted below.
Step 2: Now you will see a download prompt just accept the term and conditions and click on the download button
Step 3: If you have an oracle account then sign in or if don’t then create one and sign in
Step 4: Then your download will start automatically after signing in if don’t then click on the previous link again
Step 5: After downloading, run the jdk-8u Application(.exe file) and follow the instructions to install Java on your machine. Once you install Java on your device, you have to set up the environment variable.
Step 6: Go to Control Panel -> System and Security -> System. Under the Advanced System Setting option click on Environment Variables as highlighted below.
Step 7: Now, you have to alter the “Path” variable under System variables so that it also contains the path to the Java environment. Select the “Path” variable and click on the Edit button as highlighted below.
Step 8: You will see a list of different paths, click on the New button, and then add the path where java is installed. By default, java is installed in “C:\Program Files\Java\jdk\bin” folder OR “C:\Program Files(x86)\Java\jdk\bin”. In case, you have installed java at any other location, then add that path.
Step 9: Click on OK, Save the settings, and you are done !! Now to check whether the installation is done correctly, open the command prompt and type javac -version. You will see that java is running on your machine.
Note: To make sure whether the compiler is set up, type javac in the command prompt. You will see a list related to javac.
B. Linux Operating System
In Linux, there are several ways to install java. But we will refer to the simplest and easy way to install java using a terminal. For Linux, we will install OpenJDK. OpenJDK is a free and open-source implementation of the Java programming language. Steps for setting the environment in the Linux operating system are as follows:
Step 1: Go to Application -> Accessories -> Terminal.
Step 2: Type the command as below as follows:
sudo apt-get install openjdk-8-jdk
Step 3: For the “JAVA_HOME” (Environment Variable) type the command as shown below, in “Terminal” using your installation path…(Note: the default path is as shown, but if you have to install OpenJDK at another location then set that path.)
export JAVA_HOME = /usr/lib/jvm/java-8-openjdk
Step 4: For “PATH” (Environment Value) type command as shown below, in “Terminal” using your installation path…Note: the default path is as shown, but if you have to install OpenJDK at another location then set that path.)
export PATH = $PATH:/usr/lib/jvm/java-8-openjdk/bin
Note: We are done setting up the environment in Java for Linux OS.
- Notepad/gedit : They are simple text-editors for writing java programs. Notepad is available on Windows and gedit is available on Linux.
- Eclipse IDE : It is the most widely used IDE(Integrated Development Environment) for developing software in java. You can download Eclipse.
C. MacOS Operating System
Step 1: Open the terminal from the application folder or simply press the “command” and “shift” key together and write initials of the terminal and press enter.
It will be good to have package manager such as homebrew installed in your machine as we can operate to install any software from here itself simply by using terminal commands.
Step 2: Now in order to configure first write the command ‘java –version ‘ where the message below it will pop that there is no
java --version javac --version
Note: If it was set up then you would have been getting the version displayed on the screen as it is shown below where in that machine it was already set up. So remember to cross-check in your machine once you have successfully set it up in yours.
Step 2: Once we are done with installing JDK now let us move on setting up the java_home environment variable for that you will have to look into something called s ‘bash_profie’ using the below command
You will notice that in your terminal there will be no bash_profile set but it is shown below so here in this machine it is already set up. In order to set it up if not there we have to create it which lets us prior seek into java home variables whether it is set up or not.
Step 3: Setting up the home java variable. Use the below command to check or setup if not installed as follows on the terminal:
If it is showing blank then the java home variable is not set up as perceived from the above image.
Step 4: Installing bash_profile
Make sure to go to the root folder in the terminal and write the command ‘touch ./bash_profile ‘
Now you will see that bash-profile s created which is as shown in the step2 in your machine which hone can verify by writing command as follows:
Step 5: Edit the .bash_profile created for java, you just have to write the command marked in below media and provided below as follows:
export JAVA_HOME=$(/usr/libexec/java_home) // No need to remember this command
Save this file and relaunch the terminal by closing it.
Step 5: Verifying whether it is installed by entering the following two commands
source .bash_profile echo $JAVA_HOME
From the above media, we can see the java variable is all set to go as earlier there was a blank therein the above media.
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.
and under the Java directory the JDK is residing.
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.
In the system properties, we will navigate to the Advanced tab which provides the Environment Variables button like below.
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.
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 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 .
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.
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, где она используется и как её корректно указать.