Recently, I encountered a situation where I needed to install Java on my macOS machine, and the easiest way to get it up and running was through Homebrew. Whether you’re working with Java-based applications or development environments like Android Studio, having the right Java version installed is crucial. In this post, I’ll walk you through how I quickly resolved the issue using Homebrew.
Thank me by sharing on Twitter 🙏
Why Install Java with Homebrew?
The great thing about using Homebrew is that it simplifies package management on macOS. You can install, update, and switch between versions of software like Java seamlessly. If you’ve ever struggled with manually downloading and managing Java versions from Oracle’s website, Homebrew is the better alternative. It helps you stay up to date and manage Java versions easily.
Initially I got this error:
>java -version
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.How to Install Java via Homebrew
Let me take you through the steps to get Java installed on your machine.
First, open your terminal and run the following command to install the latest version of OpenJDK:
Thinking in Systems: International Bestseller
$10.72 (as of February 27, 2026 20:38 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Syntech USB C to USB Adapter Pack of 2, USB 3.0 Female to Thunderbolt 4/3 Adapter Compatible with MacBook Pro Air 2024, Surface, iPad, iPhone, Galaxy Notebook, XPS and More Type C Devices, Space Grey
$7.99 (as of February 28, 2026 05:14 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Car Carplay Cable for iPhone 17 15 16 /Air/ Pro Max, USB A to USB C for Carplay for iPhone USB Cord, Car Charger for IPhone 17 Air Charging Cable, iPad Pro, iPad Air 5th, Mini 6th Gen Car Charger Cord
$7.99 (as of February 28, 2026 05:14 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)brew install openjdkAfter Homebrew completes the installation, you might need to link Java so your system can find it:
sudo ln -sfn $(brew --prefix openjdk)/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdkTo confirm the installation, simply check the Java version:
java -versionNow, if you need a specific version of Java, Homebrew makes that easy too. You can install it by specifying the version:
brew install openjdk@22This flexibility comes in handy when working on projects that require older or specific Java versions. You can even install Oracle’s JDK if you prefer, using the following command:
brew install --cask temurinConclusion
By using Homebrew to install Java, I was able to simplify the whole process of managing Java versions on my macOS machine. Whether you need the latest OpenJDK or a specific version, Homebrew provides a clean and efficient way to get set up without downloading installers or dealing with manual configurations. Now, switching between Java versions is as simple as a command. If you’re looking to streamline your Java setup, I definitely recommend giving this approach a try.



> You can even install Oracle’s JDK if you prefer, using the following command:
> brew install –cask temurin
Temurin, formerly known as AdoptOpenJDK, is the Eclipse Foundation’s binary build of OpenJDK. If you want Oracle’s JDK, it’s: brew install –cask oracle-jdk