Explain Codes LogoExplain Codes Logo

How to install Java 8 on Mac

java
java-8
homebrew
java-version-management
Anton ShumikhinbyAnton Shumikhin·Sep 19, 2024
TLDR

In the world of Mac, admins Homebrew reigns supreme. Quickly install Java 8 using:

brew tap AdoptOpenJDK/openjdk && brew install --cask adoptopenjdk8

Post-install, confirm all went well with java -version. If Java 8 refuses to reign as default, give it a nudge by adding:

echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)' >> ~/.zshrc && source ~/.zshrc

Crowned king, Java 8 now rules all current and future terminal sessions.

Keeping Java untangled: Homebrew

Before taking the leap, let's furnish our toolkit and update Homebrew:

brew update # "Updating Homebrew... also, remember to take a coffee break!"

If you are seeking an easy way to manage OpenJDK versions, including Java 8, use Homebrew to install additional Java versions:

brew tap homebrew/cask-versions # "Tapping into the multiverse of Java versions... brace for impact!

To effortlessly switch between installed Java versions, the java_home utility is your knight in shiny terminal.

Encounter trouble with multiple versions or conflicts? Fire your arrows with:

brew untap adoptopenjdk/openjdk & brew untap caskroom/versions # "Because sometimes, less is more!"

Beware, brave programmers. The Oracle path is dark and fraught with license restrictions. Enter with caution!

Solutions for referring Mac to Java 8

Mixing up multiple tabs on Homebrew? Here is the antidote:

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

If, by some dark magic, java_home stubbornly sticks to Java 1.6, fear not. Append the path to your .bash_profile to guide your Mac to Java 8.

echo 'export PATH="/usr/local/opt/openjdk@8/bin:$PATH"' >> ~/.bash_profile # "Set the PATH... may the source be with you!"

And if you are battling not just with Java but also IDEs such as IntelliJ, don't forget to adjust your Project Structure settings post-installation to ensure compatibility with Java 8.

Alternate paths: SDKMAN!

Introducing SDKMAN!, the cross-platform friend for Java version management. To install SDKMAN! and manage Java versions, run:

curl -s "https://get.sdkman.io" | bash # "Downloading SDKMAN!... who said programmers can't also be superheroes?"

Once you're powered by SDKMAN!, behold your Java versions and install Java 8:

sdk list java && sdk install java 8.0.<version>-<dist> # "Here's a list of all the different ways you can say 'Hello World' in Java."

To confirm your mastery of Java versions:

java -version # "Verifying your Java version... or as we like to call it, peek-a-boo!"

Find java_home returning to a former love? Steer it back on track by manually specifying the Java path, especially useful with legacy systems or specific tools.

Staying tidy: Maintenance tips

Just as you need your coffee breaks, your code needs a tidy up too with:

brew cleanup # "Cleanup on aisle /usr/local/Cellar!

This helps keep your Homebrew brews fresh by deleting obsolete formulae and dropping unused files. For bug alerts and fixes, keep an eye on Homebrew's GitHub repository.

And lastly, take note, the Java version adorning your System Preferences may not be the one doing the backstage hard work. So, always double-check your command-line improvisations!