HomeJava

Step by Step tutorial to set Java Path

Step by Step tutorial to set Java Path
Like Tweet Pin it Share Share Email

One of the most basic steps to work with java is to set your path variable so that you can compile and run your java related commands from the location where your java programs reside and not from the bin directory of JDK.

You might get this error in case the path is not set in environment variables:

‘javac’ is not recognized as an internal or external command, operable program or batch file

Error when java path is not set in path variable
Error when java path is not set in path variable

Follow the below step by step instructions to set the java path in windows environment variable:

  • Make a note of the bin directory path of java and keep it available.
  • Right click on Computer and select Properties context menu.
My Computer > Properties
My Computer > Properties
  • Click on advanced System Settings.
Navigate to advanced System Settings
Navigate to advanced System Settings
  • Click on Environment Variables button of System Properties Window under “Advanced” tab.
System Properties > Advanced > Environment Variables
System Properties > Advanced > Environment Variables
  • Now in the “Environment Variables” window under “System Variables” section, scroll to see the variable by name path, select and click on edit.
Edit Path Environment Variable
Edit Path Environment Variable
  • You will now be presented with a small window with variable name and value, go to the end of the variable, make sure you add one semi colon at the end of the current value in case it is not there and then paste your bin directory path, for example: as per my machine it is “C:\Program Files\Java\jdk1.8.0_91\bin” without double quotes, you need to form this based on the location java is installed in your machine and click on Ok button.
Set Java Bin directory in Path variable
Set Java Bin directory in Path variable
  • Click on Ok buttons to close the parent windows as well.
  • You are done with setting the path variable successfully, in order to verify if everything is fine, open a new command prompt, change directory to “c:\” drive using the command “cd \” without double quotes.
  • Now try the javac command and you shall see the following message, which means, the variable is set properly and from now you can create your java programs in your desired location.
Javac working from different folder locations
Javac working from different folder locations

Finally you are all set to compile and run your java programs from your desired folder location.

Share your queries in form of comments, we would be more than happy to help

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *