Open In App

How to Set Temporary and Permanent Paths in Java?

Last Updated : 12 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Java, the most important task is to set the environment variable on the system. If the Java source file is inside the jdk/bin folder, the path is not required to be set because tools like javac, and java can be accessed globally on the system. If the Java source file is outside the jdk/bin folder, then either a temporary or permanent Java path is required to be set in order to execute the Java source file.

Ways to Set Java Path

There are two ways to set the Java path, that are:

  • Temporary Path
  • Permanent Path

Now, we are going to discuss how to set the temporary Java path in depth.

Setting Temporary Java Path

To set, the temporary Java path we need to follow the steps which are mentioned below:

  • Open command prompt
  • Copy the path of jdk/bin directory (e.g. C:\Program Files\Java\jdk-24\bin)
  • In the Command Prompt, write the following command

SET PATH=C:\Program Files\Java\jdk-24\bin

Note: This command sets the path for the current prompt session and when the session is closed the path will no longer be valid.

StepsToFollow

Note: This is used only when we need to use Java for a short time and we do not want to make permanent changes to the system

Now, we are going to discuss how to set the Permanent Java path in depth.

Setting Permanent Java Path

To set the permanent Java path we need to follow the steps which are mentioned below:

Go to Control Panel > System and Security > System.

ControlPanel


On the left panel, click on Advanced system settings.

AdvanceSystemSetting


In the System Properties window, click on the Environment Variables button.

SystemProperty


Under the System variables, find and select the variable path.

  • Select the Path variable and click Edit.
  • In the Edit Environment Variable window, click New, and then paste the path of the bin folder.
EditEnvironmentVariable


Click OK to save the changes. Click OK in the Environment Variables window to apply the changes.

Note: To make changes to the Path variable take effect, you might need to restart the Command Prompt or your computer.

This is how we can set both temporary and permanent paths for Java on a Windows system.

Why Set Permanent Java Path?

When we set the path permanently, it makes Java commands like java and javac available every time, when we open a Command Prompt and because of this we do not need to set the path again and again.

How to Verify the Java Path?

After setting the path, we can verify that it sets correctly by checking the version of Java from the command prompt.

Type the following command which is listed below:

java -version

If it sets correctly, we will see the version information in the command prompt. It will confirm that the path is working correctly.

Like this we, can also check the compiler version

javac -version

If we get the Java version on the command prompt, it means the path is set correctly.


Article Tags :
Practice Tags :

Similar Reads