Setting Java Path
To set the path in Java, you need to follow the below steps:
- Open your system properties by right-clicking on the "My Computer" or "This PC" icon on your desktop and selecting "Properties".
- Click on the "Advanced system settings" link.
- Click on the "Environment Variables" button.
- In the "System Variables" section, scroll down until you find the "Path" variable and select it.
- Click on the "Edit" button.
- In the "Variable value" field, append the location of your Java installation's "bin" folder to the end of the string. Make sure to separate each path with a semicolon (;).
For example, if your Java installation is located in "C:\Program Files\Java\jdk1.8.0_181", you would add ";C:\Program Files\Java\jdk1.8.0_181\bin" to the end of the "Variable value" field.
- Click "OK" to close all windows.
After setting the path, you should be able to run Java commands from anywhere in the command prompt or terminal.
How to set the Temporary Path of JDK in Windows
To set the temporary path of JDK in Windows, you can follow these steps:
Open the Start menu and search for "Environment Variables."
Click on the "Edit the system environment variables" option.
In the System Properties window, click on the "Environment Variables" button.
In the Environment Variables window, scroll down to the "System variables" section and find the "TEMP" variable.
Click on the "Edit" button for the "TEMP" variable.
In the Edit Environment Variable window, add the path to your JDK's "bin" directory to the "Variable value" field. For example, if your JDK is installed in "C:\Program Files\Java\jdk-11", you would add "C:\Program Files\Java\jdk-11\bin" to the end of the existing value, separated by a semicolon (;).
Click "OK" to save the changes and close all windows.
Now the temporary path of your JDK is set in Windows. This will enable you to run Java applications that require the JDK and also allow the Java compiler (javac) to create temporary files in the specified directory.
How to set Permanent Path of JDK in Windows
To set the permanent path of JDK in Windows, follow the steps below:
Find the location of the JDK installation directory on your computer. The default location for JDK installation is C:\Program Files\Java\jdk_version.
Right-click on "My Computer" or "This PC" and select "Properties" from the context menu.
Click on "Advanced System Settings" in the left-hand panel.
Click on the "Environment Variables" button.
Under "System Variables", scroll down and find the "Path" variable. Select it and click on the "Edit" button.
In the "Edit environment variable" window, click on the "New" button and enter the path to the JDK installation directory that you found in step 1. Make sure to separate it from the existing entries with a semicolon (;).
Click "OK" to close all the windows.
Open a new command prompt window or restart any existing ones to ensure the changes take effect.
You have now set the permanent path of JDK in Windows. You can verify that the path has been set correctly by running the command "javac -version" in the command prompt. If the command shows the version of the JDK installed, then the path has been set correctly.
Setting Java Path in Linux OS
To set the Java path in Linux, follow the steps below:
Open a terminal window.
Check if Java is installed on your system by running the following command:
java -version
If Java is not installed, you can install it using the package manager for your Linux distribution.
Once you have verified that Java is installed, find the installation path of the Java Development Kit (JDK) by running the following command:
bashreadlink -f $(which java) | sed "s:bin/java::"
This command will output the installation path of the JDK.
Open the "/etc/environment" file in a text editor with root privileges:
bashsudo nano /etc/environment
In the file, add the following line at the end, replacing the path with the installation path of the JDK that you found in step 3:
makefileJAVA_HOME="/path/to/jdk"
Save the changes and exit the text editor.
Reload the environment variables by running the following command:
bashsource /etc/environment
This will make the changes to the environment variables take effect immediately.
Verify that the Java path has been set correctly by running the following command:
bashecho $JAVA_HOME
- This command should output the installation path of the JDK that you set in step 5.