Java – Set Path in Java

  • Post category:Java
  • Reading time:5 mins read

How to set path in Java

  • PATH is a system variable that the operating system uses to find the required executable file from the command line or terminal window.
  • You can configure the PATH system variable using the System utility in Windows Control Panel or in the Linux and Solaris shell startup files.

If you save your Java source files inside the JDK / bin directory, you don’t need to set the path since all the tools are available in the current directory.
However, if you have Java files outside of the JDK / bin folder, you will need to set the path to your JDK.

How to set Java Path in Windows

Windows 10 and Windows 8

  • Click window icon from Keyboard and search : View advanced system setting
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
  • Reopen Command prompt window, and run your java code.

Windows 7

  • From the desktop, right click the Computer icon.
  • Choose Properties from the context menu.
  • Click the Advanced system settings link.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
  • Reopen Command prompt window, and run your java code.

Windows Vista

  • From the desktop, right click the My Computer icon.
  • Choose Properties from the context menu.
  • Click the Advanced tab (Advanced system settings link in Vista).
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
  • Reopen Command prompt window, and run your java code.

Windows XP

  • Select Start, select Control Panel. double click System, and select the Advanced tab.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
  • Reopen Command prompt window, and run your java code.

For Example:

If we have to set below path :

C:\Program Files\Java\jdk1.6.0_20\bin

1) Go to My Computer properties

2) Click on the Advanced system settings link

3) Click on Environment variables and Click on the New tab to add

5) Write the “path” in the variable name

6) Copy the path of bin folder

Setting Java Path in Linux OS

The Linux operating system path settings are the same as the Windows operating system path settings. However, we will use the export tool instead of the settings here. Let’s see how to set the path in the Linux operating system.

export PATH=$PATH:/home/jdk1.6.0.20/bin/