A Step-by-Step Guide to Installing Java with Brew

Published on 2024.02.19

Java is a widely-used programming language that is essential for many applications and systems. In this guide, we will walk you through the installation process of Java using Brew, a popular package manager for macOS.

Step 1: Install Homebrew

Before you can install Java with Brew, you need to have Homebrew installed on your macOS system. If you haven't installed it yet, follow these steps:

  1. Open the Terminal.
  2. Enter the following command:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Press Enter and follow the instructions to complete the installation.

Step 2: Update Homebrew

It's always a good idea to update Homebrew before installing any packages. To update Homebrew, run the following command in the Terminal:

brew update

Step 3: Install Java

Now that Homebrew is installed and up to date, you can easily install Java by running the following command:

brew install openjdk

This command will install the latest version of Java available through Homebrew. If you need a specific version of Java, you can specify it in the command, for example:

brew install openjdk@11

Step 4: Verify the Installation

To verify that Java has been successfully installed, run the following command in the Terminal:

java -version

You should see the version information of Java printed in the Terminal.

Step 5: Set the JAVA_HOME Environment Variable

To ensure that Java is properly configured on your system, you need to set the JAVA_HOME environment variable. Add the following line to your ~/.bash_profile or ~/.zshrc file:

export JAVA_HOME="/usr/local/opt/openjdk"

Save the file and run the following command to apply the changes:

source ~/.bash_profile


In this guide, you have learned how to install Java using Brew on macOS. By following these steps, you can quickly set up Java on your system and start building Java applications.