How to setup and configure java for development or testing

Posted on

If you are new to Java programing language and you want to learn Java, then the first step is to have JDK installed and configured in your system. This blog will guide you to setup the environment for Java development or testing.

Step 1 : Installation

You can download JDK from your oracle website using this link. Chose the correct download link for your operating system. The installation is quite straight forward, you need to run the executable file and follow the default instruction in the setup window.

Step 2 : Set Environment Variables

Once the installation is completed, you need to set the environment variables for java to work. Following are the entries you need to make.

  • Java_Home
  • Path

JAVA_HOME environment variable should be your JDK installation directory. We need to set this variable as some of the dependent programs can access the JDK or JRE. For example Maven, Gradle, Apache Tomcat etc use JAVA_HOME as the relative path to locate the JDK or JRE.


To run a java native application, operating system need to locate the bin directory of JDK. This can be accomplished by adding the JDK bin directory to the PATH variable.

The path you must set for your system depending on the operating system is as follows:-

For Windows:

  • JAVA_HOME = C:/Program Files/Java/jdk-20
  • PATH = C:/Program Files/Java/jdk-20/bin
To set JAVA_HOME, follow below steps:
  • Right Click on My Computer or This PC icon on desktop
  • Click on Properties
  • Under Related Settings, click on Advanced system settings
  • On System Properties window click on Environment Variables button
  • On Environment Variables window, under user variables, click on New
    • Enter Variable name : JAVA_HOME
    • Enter Variable value : C:\Program Files\Java\jdk-20
  • Click on Ok
To set PATH, follow below steps:
  • Under System variables, locate variable name Path
  • Click on Edit
  • Click on New
  • Add C:/Program Files/Java/jdk-20/bin
  • Click on Ok
  • Click on Ok on Environment variables window
  • Click on Ok on System Properties window

For MAC:

  • JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk-20
  • PATH = /Library/Java/JavaVirtualMachines/jdk-20/bin
To set JAVA_HOME and PATH on MAC, follow below steps:
  • Locate the JDK path, if not the above.
  • Open Console/Shell
  • Run command vim ~/.bash_profile
  • Press "i" to activate insert mode
  • Add following lines:
    • export JAVA_HOME="/usr/libexec/java_home" or export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-20/Contents/Home"
    • export PATH=$PATH:$JAVA_HOME/bin
  • To save and exit press Esc key, then type :w and hit Enter key
  • Run command source /etc/profile, to apply the changes.

For Linux:

  • JAVA_HOME = /usr/lib/jvm/jdk-20
  • PATH = /usr/lib/jvm/jdk-20/bin
To set JAVA_HOME and PATH on Linux, follow below steps:
  • Locate the JDK path, if not the above.
  • Open Console/Shell
  • Run command vim /etc/profile
  • Press "i" to activate insert mode
  • Add following lines:
    • export JAVA_HOME="/usr/lib/jvm/jdk-20"
    • export PATH=$JAVA_HOME/bin:$PATH
  • To save and exit press Esc key, then type :w and hit Enter key
  • Run command source /etc/profile, to apply the changes.

Step 3 : Verify Installation

To verify the installation, open command prompt and run the following command:
java --version If you are able to see the below information, then you have successfully configured java in your system. java 20.0.1 2023-04-18
Java(TM) SE Runtime Environment (build 20.0.1+9-29)
Java HotSpot(TM) 64-Bit Server VM (build 20.0.1+9-29, mixed mode, sharing)

Note :
  • The installation path might be different from the one given above. You should find the correct path during installation.
  • In this blog we have installed JDK version 20. You can chose the any other versions according to your project requirement.