Java

Installation

First you should check if Java is already installed

  1. $ java -version

If you see an output like below then Java is already installed on your machine so skip to Add Java to PATH.

  1. java version "1.8.0_45"
  2. Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
  3. Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

If you don’t see the output like above then you need to install Java on your system.

Using the Oracle installer

Please download the macOS version from the Oracle website.

Using Homebrew

  1. brew update
  2. brew tap caskroom/versions

Then, install latest version of Java 9 via:

  1. brew cask install java

or install Java 8 using:

  1. brew cask install java8

Check if Java is correctly installed by running the java -version command again.

Add Java to PATH

Add JAVA_HOME to your environment variables by adding the line below to your env.sh (see iTerm2 section if you don’t have a env.sh file).

  1. export JAVA_HOME="`/usr/libexec/java_home -v 1.8`"

If you are using Java 9, use the following:

  1. export JAVA_HOME="`/usr/libexec/java_home -v 9`"

You should have Java working now. Two popular IDE alternatives for writing Java are Eclipse or IntelliJ.