1. Install homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Update homebrew if already installed:

brew update

  1. allow brew to lookup versions

brew tap homebrew/cask-versions

  1. list available java versions

brew search java

Optional: to find out the minor version of java

brew info --cask java8

  1. install java 8 (or any other version available)

brew install --cask java8

Answer from Jubba Smail on Stack Overflow
๐ŸŒ
Lotharschulz
lotharschulz.info โ€บ 2019 โ€บ 08 โ€บ 21 โ€บ mac-change-default-java-version
Change Java version on Mac โ€“ Lothar Schulz
August 21, 2019 - $ brew cask install adoptopenjdk/openjdk/adoptopenjdk8 # which java versions installed $ /usr/libexec/java_home -V Matching Java Virtual Machines (2): 11.0.2, x86_64: "OpenJDK 11.0.2" /Library/.../openjdk-11.0.2.jdk/Contents/Home 1.8.0_222, x86_64:"AdoptOpenJDK 8" /Library/.../adoptopenjdk...
Discussions

macos - Downgrading Homebrew's default Java version - Stack Overflow
Recently i used brew upgrade and now my sbt seems to be using bersion 16 java, i cant actually find this version on my machine and need to set it back to java version 8 that is on my laptop. I have... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to set or change the default Java (JDK) version on macOS? - Stack Overflow
How can you change the default version of Java on a mac? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to remove Java 10? Or revert to the previous version? - Ask Different
The Java updater on my Mac installed an obscure version of Java 10.0.1 which I never heard before. The result is that ALL my java apps are not running anymore, which makes Java pointless. The offi... More on apple.stackexchange.com
๐ŸŒ apple.stackexchange.com
May 8, 2018
How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 - Stack Overflow
How to downgrade Java from 9 to 8 on a macOS Sierra 10.12.6(16G29) . I tried removing the Java plugin and installed Java 8, however the Java and javac version shows 9 in terminal, but In system More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ miro-engineering โ€บ how-to-switch-between-java-lts-versions-8-11-and-17-on-mac-cb6717d1272
How to switch between Java LTS versions 8, 11, and 17 on Mac | by Lothar Schulz | Miro Engineering | Medium
November 25, 2021 - Setting the symlink after every installation step is important for the system Java wrappers to find the installed JDK. Installing JDKs with brew also recommends adding /usr/local/opt/openjdkXX/bin to PATH.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 69093041 โ€บ downgrading-homebrews-default-java-version
macos - Downgrading Homebrew's default Java version - Stack Overflow
You can either forcibly set JAVA_HOME to the JDK 8 path on disk (which is what sdkman will do), or you can uninstall the java 16 with homebrew since openjdk@8 will not update to 16 with brew upgrade.
๐ŸŒ
Medium
medium.com โ€บ @haroldfinch01 โ€บ step-by-step-guide-installing-and-switching-java-versions-on-mac-osx-f3896b9872f4
Step-by-Step Guide: Installing and Switching Java Versions on Mac OSX | by Harold Finch | Medium
May 21, 2024 - Step-by-Step Guide: Installing and Switching Java Versions on Mac OSX To install Java on macOS and allow for easy switching between different versions, you can use a version manager like jenv. Here's โ€ฆ
๐ŸŒ
Quora
quora.com โ€บ How-do-I-downgrade-Java-on-Mac
How to downgrade Java on Mac - Quora
Answer: You can install multiple versions of the JDK simultaneously. Look in /Library/Java/JavaVirtualMachines/ to see which versions are currently installed. There is a folder named CurrentJDK, which is actually a symbolic link to one of the other folders. Remove it and create a new symbolic ...
๐ŸŒ
GitHub
gist.github.com โ€บ gwpantazes โ€บ 50810d5635fc2e053ad117b39b597a14
How to install different JDK versions on MacOS with Homebrew ยท GitHub
I recommend jEnv for switching between multiple Java environments on MacOS. I think it's generally wise to have homebrew/cask and homebrew/cask-versions tapped. They are practically core. SDKMAN is a SDK downloader and manager that can be a viable alternative to Homebrew for installing JDKs and even managing them. ... There has since been a change to the steps. I believe the recent ones I've come across are: $ brew ...
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ reachnow-tech โ€บ change-default-java-version-on-mac-a7f01647f126
Change default Java version on Mac | by Lothar Schulz | reachnow-tech | Medium
September 6, 2019 - How to change default java version on Mac from Java version 11.0.2 to Java version 1.8 to enable a service transition.
๐ŸŒ
Lotharschulz
lotharschulz.info โ€บ 2021 โ€บ 11 โ€บ 30 โ€บ how-to-switch-between-java-lts-versions-8-11-and-17-on-mac
How to switch between Java LTS versions 8, 11 and 17 on Mac โ€“ Lothar Schulz
# version 17 brew install openjdk@17 sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk # version 11 brew install openjdk@11 sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk # version 8 brew install openjdk@8 sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk
๐ŸŒ
Othrif
othrif.github.io โ€บ linux โ€บ basics โ€บ java_version_mac.html
Downgrade java version in MacOS
April 12, 2020 - First check which version you are running: java --version openjdk 16.0.1 2021-04-20 OpenJDK Runtime Environment Homebrew (build 16.0.1+0) OpenJDK 64-Bit Server VM Homebrew (build 16.0.1+0, mixed mode, sharing) Download the java version you want from http://jdk.java.net/ Follow the installation ...
๐ŸŒ
Oracle
java.com โ€บ mac_uninstall_faq
How do I uninstall Java on my Mac?
To uninstall JDK 7 and later versions, you must have Administrator privileges and execute the remove command either as root or by using sudo.
Top answer
1 of 9
2

Here is how I do it on my Linux (Ubuntu / Mint mate), I guess Mac can do it similarly.


Install & config

Steps:

  • [Basic - part]
  • Download jdk (the .tgz file) by hand.
  • Uncompress & rename properly, at a proper location.
    e.g /mnt/star/program/java/jdk-1.8
  • Make a soft link, which will be changed to switch java version later.
    e.g ln -s /mnt/star/program/java/jdk-1.8 /mnt/star/program/java/java
    Thus /mnt/star/program/java/java is the soft link.
  • Set JAVA_HOME in a start script.
    Could use file like /etc/profile.d/eric.sh, or just use ~/.bashrc.
    e.g JAVA_HOME=/mnt/star/program/java/java
  • Then open a new bash shell. java -version should print the java version.
  • [More version - part]
  • Download & install more Java version, as need, similar as above steps.
    e.g
    /mnt/star/program/java/jdk-11
  • [Switch - part]
  • In ~/.bashrc, define variable for various Java version.
    e.g
    _E_JAVA_HOME_11='/mnt/star/program/java/jdk-11'
    _E_JAVA_HOME_8='/mnt/star/program/java/jdk-8'
    # dir of default version,
    _E_JAVA_HOME_D=$_E_JAVA_HOME_8
  • In ~/.bashrc, define command to switch Java version.
    e.g
    ## switch java version,
    alias jv11="rm $JAVA_HOME; ln -s $_E_JAVA_HOME_11 $JAVA_HOME"
    alias jv8="rm $JAVA_HOME; ln -s $_E_JAVA_HOME_8 $JAVA_HOME"
    # default java version,
    alias jvd="rm $JAVA_HOME; ln -s $_E_JAVA_HOME_D $JAVA_HOME"
    alias jv="java -version"
  • In terminal, source ~/.bashrc to make the changes take effect.
  • Then could switch using the defined commands.

Commands - from above config

Commands:

  • jv11
    Switch to Java 11
  • jv8
    Switch to Java 8
  • jvd
    Switch to default Java version, which is denoted by _E_JAVA_HOME_D defined above.
  • jv
    Show java version.

Example output:

eric@eric-pc:~$ jv
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

eric@eric-pc:~$ jv11
eric@eric-pc:~$ jv
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

eric@eric-pc:~$ jvd
eric@eric-pc:~$ jv
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

eric@eric-pc:~$ 

Mechanism

  • It switch by changing the soft link, which is used as JAVA_HOME.

Tips

  • On my machine when install jdk by hand, I keep the minor version, then make a soft link with the major version but without the minor version.
    e.g
    // this is the actual dir,
    jdk1.8.0_191

    // this is a soft link to jdk1.8.0_191
    jdk-8

    // this is a soft link to jdk-8 or jdk-11
    java

  • I define command alias in ~/.bashrc, but define variable in a separate file.
    I am using ~/.eric_var to define the variables, and ~/.bashrc will source it (e.g source $HOME/.eric_var).

2 of 9
2

A very simple way to change the default Java version on MacOS via HomeBrew:

Start with:

brew install openjdk@17

Once it completes. Run:

sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

Enter your machine's password and finally run the 2 commands one after another.

export JAVA_HOME=$(/usr/libexec/java_home -v 17) // Specify your own version
export PATH=$JAVA_HOME/bin:$PATH

Check Java Version:

java -version

You're good to go:

openjdk version "17.0.14" 2025-01-21
OpenJDK Runtime Environment Homebrew (build 17.0.14+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.14+0, mixed mode, sharing)
Top answer
1 of 5
4

I had this same problem: I had Java 8 installed, but later installed 10. Then, I removed 10, and when I launched a jar from the terminal it would run in version 8, and when I checked the version with java -version in the terminal I would get back java version "1.8.0_181. However when I ran a .jar from the Finder, it would run in v.10, and also if I went to the Java preference pane the version was listed as version 10. This was undesirable: I was trying to remove v10 completely.

Then, I deleted JavaAppletPlugin with rm /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin and reinstalled Java SE JDK 8 from online, and lo! it works now. When I run .jar, they run in Java 8.

I realize you mentioned this in your first step, but I infer that you didn't do this step? If I'm wrong about that then you've got a different problem. But this solved mine.

2 of 5
49

I believe the problem is navigating to the correct directory... Once you are where you are supposed to be you can run the sudo commands to remove whichever versions of java you want to remove.

First, run the command in the terminal to determine which version of Java you are running,

java -version

then you can navigate to pesky version of java that you intend to delete by using the following command:

cd /Library/Java/JavaVirtualMachines

then once you see are in the JavaVirtualMachines path, type in ls to see what versions of Java you have installed,

ls

and finally when you know which version or versions of Java you want to uninstall:

sudo rm -rf jdk-10.0.1.jdk #or whichever version you want to delete
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ what-is-the-best-way-to-update-java-version-on-mac-computer
How to Update Java Version on Mac: Best Methods (Brew, Web, & Alternatives) โ€” javathinking.com
(For Apple Silicon Macs, replace /usr/local with /opt/homebrew.) If you have multiple Java versions installed (e.g., Java 11 and 17), use brew link to switch:
๐ŸŒ
University of Oregon
service.uoregon.edu โ€บ TDClient โ€บ KB โ€บ ArticleDet
Reverting to a Previous Version of Java (macOS)
January 31, 2018 - This page explains how to uninstall your current version of Java and then install an older version. These instructions focus on Java 8.
๐ŸŒ
Apple Community
discussions.apple.com โ€บ thread โ€บ 4513733
How can I downgrade my Java version and Rโ€ฆ - Apple Community
Go to /System/Library/Java/JavaVirtualMachines/ and delete anything whose name starts with jdk1.7.0 or says Java 7 or something similar. ... Hi. I am currently working on 10.8.4 OSX. I had accidentally installed jdk1.7, downloaded and installed it from oracle site, and now have to downgrade it.
๐ŸŒ
DEV Community
dev.to โ€บ rithvik78 โ€บ change-the-default-java-version-on-macos-3jee
Change the default Java Version on macOS - DEV Community
February 19, 2022 - Here, We are trying to change the version to Java SE 8 First run /usr/libexec/java_home -V which... Tagged with macos, java, jdk, javase8.
๐ŸŒ
Liangzhou
liangzhou.dev โ€บ home โ€บ manage multiple java versions on mac o s using brew and jenv
Manage multiple java versions on macOS using brew and jenv - TODO Learn More
Install and Update on macOS Manage multiple java versions on macOS can be tricky. There's different ways to install: homebrew cask download java distribution from Oracle download java distribution from java.com And once the java version becomes outdated, there's different ways to upgrade too, ...