A Step-by-Step Guide to Installing Java on macOS

Tejaksha K
3 min readAug 5, 2023


Java is a versatile and widely-used programming language that powers a vast array of applications, from web and mobile apps to enterprise systems. If you’re a macOS user looking to install Java on your machine, this step-by-step guide will walk you through the process and get you ready to start developing and running Java applications.

Step 1: Check Java Version (Optional)

Before proceeding with the installation, you may want to check if Java is already installed on your macOS. Open Terminal and enter the following command:

java -version

If Java is already installed, the command will display the version of Java you have. If not, proceed with the installation steps below.

Step 2: Download Java Visit the official Oracle Java website


To download the Java Development Kit (JDK) for macOS. JDK includes the Java Runtime Environment (JRE) and development tools necessary for Java development.

Step 3: Install Java

Once the JDK package is downloaded, locate the .dmg file, and double-click to open it. This will mount the disk image, and you will see the JDK package inside.

  • Install JDK: Double-click the JDK package icon to start the installation process. Follow the on-screen instructions to complete the installation.
  • Verify Installation: After installation, open Terminal again and enter the following command to verify that Java is installed correctly:
java -version

You should now see the Java version information displayed in the Terminal.

Step 4: Set JAVA_HOME Environment Variable (Optional but recommended)

To make Java accessible system-wide and ensure compatibility with various development tools, you can set the JAVA_HOME environment variable.

  • Find JDK Path: To find the path to your JDK installation, enter the following command in Terminal:

Copy the output path, which typically looks like “/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home” for JDK 20.

  • Set JAVA_HOME: Open Terminal and edit your .bash_profile or .bashrc file using a text editor (nano, vi, etc.):
nano ~/.bash_profile

Add the following line to the file, replacing the path with your JDK installation path:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home

Save the file and exit the text editor. Then, run the following command to apply the changes:

source ~/.bash_profile

Step 5: Verify JAVA_HOME

After setting the JAVA_HOME environment variable, verify that it is set correctly by entering:


You should see the path to your JDK installation displayed in the Terminal.

Conclusion: Congratulations! You have successfully installed Java on your macOS machine. Now you can start developing and running Java applications. Whether you’re building desktop applications, web services, or Android apps, having Java installed provides you with the necessary tools to explore the vast possibilities of this versatile programming language.



Tejaksha K

I'm a Full Stack Developer & Cloud Expert with experience in Google Cloud Platform & AWS. Passionate about learning & expanding my skills in Web Development.