on
Installing Java on MacOS
Java is no longer pre-installed with MacOS, but it’s easy to set-up your machine for Java development - in this post I discuss two popular approaches.
Although new versions of Java are released every 6 months, unless you’re going to be using new features of the langauge, I recommend installing a long term support (LTS) version.
As I’m writing this, Java 17 is the latest LTS version. You can see the Java release schedule here.
The easiest way to install Java is to use a pre-built binary for your operating system. I use Adoptium - they’re well supported and backed by likes of Microsoft, Redhat and IBM.
If you have the Homebrew package manager installed, then you can run the following commands in your terminal which will install Java.
brew install --cask temurin
Or you can download the installer from the Adoptium website.
On the site you can filter the available downloads by operating system, architecture, package type and version - once you find the version you want, download the .pkg file.
Since I’m installing Java on macOS Monterey on my Macbook M1, I’ve selected x64 architecture - if you’re using an Intel powered Mac, choose x86.
Once downloaded, launch the installer (.pkg file)
The installer will walk you through the installation. You can accept the default options.
Whichever approach you use, you can check which version of Java is installed by running the following command in the terminal:
> java --version
openjdk 18.0.2.1 2022-08-18
OpenJDK Runtime Environment Temurin-18.0.2.1+1 (build 18.0.2.1+1)
OpenJDK 64-Bit Server VM Temurin-18.0.2.1+1 (build 18.0.2.1+1, mixed mode)
That’s it. You’re now ready to start writing Java programs.