Setting up environment for Java

Setting up environment for Java

We have now understand what is Java, it’s features and how it is working internally. Now, it is time to setup your machine to write and run java programs. In this tutorial, I will explain each and every step in order to setup your local environment for Java.

So let’s get started.

Step 1 : Download Java

First you need to download Java which is basically (JDK – Java Development Kit) from official website of Oracle Download Java Development Kit version 1.7

setting up environment for java
setting up environment for java


Download as per your Operating system like Unix, Solaris, Windows and according to the platform like 64 bit or 32 bit machine.

Step 2 : Install JDK on your machine

Next step is to install Java on your machine. You just need to follow the instructions while installing the jdk on your system. Installation may be different on different operating system.

Step 3 : Set path for the Java tool

After you have successfully installed Java on your machine. You need to set path of the Java tool in your system environment variable. After that you will be able to execute programs.

Basically all the tools required to run a java program resides inside jdk/bin folder. So we need to set path up to this location.

location_of_your_jdk/jdk/bin

There are two ways to execute your program. Either you place your class files inside jdk/bin folder and execute. Or you need to tell the system from where to pick java tools.

There are two ways to set path.

Temporary – temporary path exist till the console is open.
Permanent – once set, you can run your program from any location.

How to set temporary path in Windows

You can run below command to set temporary path in command prompt :

set path = location_of_jdk_folder\jdk\bin

How to set path permanently in Windows Machine

Follow the below steps in order to set path in windows machine :

Click on Start button -> Right Click on My Computer -> Click on properties
On left side click on -> Advanced System Settings
System Properties pop up screen will open, then click -> Environment Variables under Advanced Tab
Environment Variables pop up screen will open, then you will see User variables list and system variables list.

Find “path” variable under system variable list and double click as below :





Then go to Variable Value and reach to the end of the value and paste the path as below

;path_to_jdk_folder\jdk\bin

For example : C:\Program Files\Java\jdk1.7.0_71\bin

Click ok, ok and ok.

How to set path on Ubuntu/Linux Machine

To set JAVA_HOME environment variable, do the following:

  1. Launch Terminal by pressing Ctrl+Alt+T on your keyboard.
  2. Enter the following command:
    $ gksudo gedit /etc/environment
  3. Depending on where you installed your Java, you will need to provide the full path. For this example, I installed Oracle JDK 7 in the /usr/lib/jvm/java-7-oracle directory.
    Scroll to the end of the file and enter the following:
    JAVA_HOME=/usr/lib/jvm/java-7-oracle
    export JAVA_HOME
  4. Save your file and exit gedit.
  5. Lastly, reload the system PATH with the following command:
    $ . /etc/environment


How to set path in Mac Machine

Please follow the below instructions in order to set path on Mac machine.


create the bash_profile:

$ vim ~/.bash_profile 

add this to the file:

export JAVA_HOME=$(/usr/libexec/java_home)

execute the source command

$ source ~/.bash_profile

echo JAVA_HOME:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

Leave a Reply

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