Before setting the path, you must need the JDK based on your devices. You can download the JDK from here.
How to set the path of JDK in Windows OS?
In windows, you can set the path of the Java Development Kit (JDK) in two ways.
- Setting Temporary Path of JDK
- Setting Permanent Path of JDK
1) How to set Temporary Path of JDK in Windows
Perform the following steps to set up the temporary path of JDK in Windows OS.
- Open Command Prompt
- Copy the path of jdk/bin directory installed in your computer. Normally it is located in the C:\Program Files\Java\jdk1.8.0_91\bin
- Write in command prompt: set path=<copied_path>
set path=C:\Program Files\Java\jdk1.8.0_91\bin
Now you can run your first Java Program in the Command Terminal.
2) How to set Permanent Path of JDK in Windows
- Go to start button and Click on
- Then the System tab will appear, Click on the Advanced System Settings.
- A new popup will appear, Click on the Advanced > Environment Variables.
- A new popup for Environment Variables will appear. Click on New.
- Now go to your JDK installation directory and copy the path (Example: C:\Program Files\Java\jdk1.8.0_91\bin)
- Enter the New User Variable parameter as
- Variable Name: path
- Variable Value: (Your JDK bin path)
- Now Click OK-> OK-> OK
Check whether the path has been set or not by performing the following task:
- Open Command Prompt.
- Type java –version
- If you get the java version your path is set otherwise you’ll get an error.
Now your permanent path is set. You can now execute any program of java from any drive.
Setting Java Path in Linux OS
Setting path in Linux OS is the same as setting the path in the Windows OS. But here we use the export tool rather than set. Let’s see how to set path in Linux OS:
Here, we have installed the JDK in the home directory under Root (/home).