How do I Set or Change the PATH System Variable?

PATH is the system variable used to locate the files needed to run your operating system from the command line or from the Terminal window.
The PATH system variable is set in operating systems, using the System Utility in the control panel in Windows, and in Linux and Solaris from the shell startup files.
It is not usually necessary to make changes to the system PATH variable on computers running Windows or Mac OS X.

For Windows Operating Systems

For Windows 10 and Windows 8 Operating Systems

  • Search for and select “Control Panel” from the Search menu
  • Click on the Advanced system settings link.
  • Click Environment Variables. Find and select the PATH variable in the System Variables section. Then click edit. If there is no PATH environment variable, click New.
  • In the Edit System Variable or New System Variable window, specify the value of the PATH environment variable. Click OK to close all remaining windows.
  • Finally, reopen the command prompt window and run your java code.

For Windows 7 Operating Systems

  • Click the Computer icon in the Window on the Desktop.
  • Select Properties from the context menu.
  • Click the advanced system settings link here.
  • Click Environment Variables. Find and select the PATH environment variable in the System Variables section. By clicking 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 to close all remaining windows.
  • Finally, reopen the command prompt window and run your java code.

For Windows XP Operating Systems

  • From the Start menu, choose Control Panel. Open the Advanced tab by double-clicking System.
  • Click Environment Variables from here. Find and select the PATH environment variable in the System Variables section. Click Edit. If there is no PATH environment variable, click New.
  • Then specify the value of the PATH environment variable in the Edit System Variable or New System Variable window. Click OK to close all remaining windows.
  • Finally, reopen the command prompt window and run your java code.

For Mac OS X Operating Systems

To run a different Java version of Mac OS X operating systems, specify the full directory path as follows or use the java_home tool:

For Solaris and Linux Operating Systems

  • To find out if the path is set correctly:
    In the terminal window, enter:
    % java -version
    If it can, it will print the version of the java tool. If the version is outdated or you get the java: Command not found error, it means the path is not set properly.
  • Identify the java executables first found in your PATH variable, then click
    To the terminal window as follows:
    Enter the % which java code.

Set PATH permanently

To set the path permanently, adjust the path in your start file.
Note: This article was written for the two most popular Shells in Linux and Solaris.

Bash Shell

Edit the startup file(~/ .bashrc)

  • Change the PATH variable:
    PATH=/usr/local/jdk1.8.0/bin:$PATH
    export PATH
  • Save and close the file
  • Upload the starter file
    % . /.profile
  • Verify that the path is set by repeating the java command
    % java -version

C Shell (csh)

Edit the startup file (~/.cshrc)

  • Set the path
    set path=(/usr/local/jdk1.8.0/bin $path)
  • Save and close the file
  • Upload the starter file                                                                                                                                                        % source ~/.cshrc
  • Verify that the path is set by repeating the java command
    % java -version

I hope it was a useful article.