Update & Cleanup Java JDK Version on macOS
- 1 Purpose
- 2 List Current Version
- 3 Use SDKMan (Option 1)
- 4 Download and Install (Option 2)
This article gives the steps to update version of the Java Development Kit (JDK) for CLI and some example JetBrains applications. By default when the little auto update window pops up and you say sure to upgrade my JDK version... it does not switch a lot of applications to use the newer version, nor does it clean up the older versions. As of macOS High Sierra and JDK 1.8.0 152.
List Current Version
Use SDKMan (Option 1)
Use SDKMan to maintain your Java JDK installs.
Download and Install (Option 2)
Install Latest Version
- Download x86 and/or x64 JDK
- Run installer
List Current Home Setting
Set Java Home Version
This should be completed by the installer, but it's a good idea to double check it was set. Also, this is how you can switch between versions if needed.
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home -v 1.8.0_152 --exec javac -version
Set Environment Variables
To force the version used by some CLI apps and
General Java Vars
java_version=1.8.0_152 export JDK_HOME=$(/usr/libexec/java_home -v $java_version) export JAVA_HOME=$(/usr/libexec/java_home -v $java_version)
Jetbrain IDE Examples
Jetbrains comes with and embedded JDK these days, but if you want to force it to use the version you've installed this is one part of the setup.
export IDEA_JDK=$(/usr/libexec/java_home -v $java_version) export RUBYMINE_JDK=$(/usr/libexec/java_home -v $java_version)
Remove Older JDK Versions
- View all installed versions
- Remove all but latest and macOS installed version
sudo rm -rf /Library/Java/JavaVirtualMachines/1.6.0.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk
Set Jetbrains JDK (Optional)