java tutorial - How to set path in Java - java programming - learn java - java basics - java for beginners



  • The path is required to be set for using tools, for example, javac, java etc.
  • If you are saving the java source file inside the jdk/bin directory, path isn’t required to be set since all the tools will be available in the present directory.
  • However if you are having java file outer the jdk/bin folder, it is important to set path of JDK.
  • There are two approaches to set java path. They are:
    • Temporary
    • Permanent

How to set Temporary Path of JDK in Windows

  • To set the temporary path of JDK,
    • Open command prompt
    • copy the path of jdk/bin directory
    • write in command prompt: set path=copied_path

For Example:

set path=C:\Program Files\Java\jdk1.6.0_23\bin
click below button to copy the code. By - java tutorial - team
 temporary path java

Learn Java - Java tutorial - temporary path java - Java examples - Java programs

How to set Permanent Path of JDK in Windows

  • For setting the permanent path of JDK, you need to follow these steps:
    • Click MyComputer properties -> advanced tab -> environment variables -> new tab of user variable -> write the path in variable name -> write the path of bin folder in variable value -> ok -> ok -> ok

For Example:

Step 1

  • Go to MyComputer properties
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 2

  • Click on advanced tab
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 3

  • Click on environment variables
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 4

  • Click on new tab of user variables
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 5

  • Write path in variable name
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 6

  • Copy the path of bin folder
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 7

  • Paste path of bin folder in variable value
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 8

  • Click on ok button
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

Step 9

  • Click on ok button
 java permanent path setting

Learn Java - Java tutorial - java permanent path setting - Java examples - Java programs

  • Now your permanent path is set. You can execute any program of java from any drive.

Setting Java Path in Linux OS

  • Setting the path in Linux operating system is similar as setting the path in the Windows OS.
  • However here we use export tool sooner than set. Let's see how to set path in Linux OS:
export PATH=$PATH:/home/jdk1.6.01/bin/
click below button to copy the code. By - java tutorial - team
  • At this time, we have installed the JDK in the home directory below Root (/home).

Related Searches to How to set path in Java