How to Set Path in Java?

    To use the Java tools like javac you have to set the path to access the functionality. If you are using the directory JDK/bin for your code, you do not need to set the path, as all the tools will be available in that directory.

    But if you are saving your Java source code outside the JDK directory, you have to set the path. You can set the path as either temporary or permanent.

    Temporary JDK Path Setup in Windows

    You can follow the below steps to set the path temporarily-

    • Open a command prompt from the start menu.
    • Copy the JDK/bin folder path.
    • Paste the copied path using the below command:
    Set path= copied_path set path=C:\Program Files\Java\jdk1.6.0_23\bin

    Graph 1

    Permanent JDK Path Setup

    You can follow the below steps to set the path permanently -

    • Right-click My Computer for the setting. Step 2
    • Select Advanced system settings -> select Environment Variables -> open a new tab for the user variable. Step 3
    • Use ‘ path ’ for the variable name and copied path for the variable value. Step 4
    • Finally, click OK .

    How to Set the Java Path in Linux?

    You can set the path in Linux in the same way as we did in Windows. But in Linux, we use the export command rather than the set command.

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