
I prefer the javahome shell function below rather than adding new values to PATH. Installing JDKs with brew also recommends adding /usr/local/opt/openjdkXX/bin to PATH. Setting the symlink after every installation step is important for the system Java wrappers to find the installed JDK. That includes JAVA LTS releases 17, 11, 8: # version 17īrew install ln -sfn /Library/Java/JavaVirtualMachines/openjdk-17.jdkīrew install ln -sfn /Library/Java/JavaVirtualMachines/openjdk-11.jdkīrew install ln -sfn /Library/Java/JavaVirtualMachines/openjdk-8.jdk On Mac you can install Java/JVM with brew‘s openjdk formulae. No time? jump straight to the javahome function This post includes Java LTS version 17 and shows how to switch between Java/JDK LTS versions 8, 11 and 17. OpenJDK 64-Bit Server VM (build 15.0.Change Java version on Mac 11 BigSur & persist it is great. OpenJDK Runtime Environment (build 15.0.2+7) You should see something like below openjdk version "15.0.2"

Refer to the output message, it said openjdk is a keg-only, which means it was not symlinked into /usr/local, so we have do do this manually for us to run java command in the terminal sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk 5. If you need to have openjdk first in your PATH, run:Įcho 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' > ~/.profileįor compilers to find openjdk you may need to set:Įxport CPPFLAGS="-I/usr/local/opt/openjdk/include" Openjdk is keg-only, which means it was not symlinked into /usr/local,īecause macOS provides similar software and installing this software in Sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk => Pouring openjdk-15.0.2.big_įor the system Java wrappers to find this JDK, symlink it with This will take a few minutes brew install java You can run the following command in a terminal to get.

Openjdk: stable 15.0.2 (bottled) ĭevelopment kit for the Java programming language Once the wizard completes, Amazon Corretto 8 will be installed in /Library/Java/JavaVirtualMachines/. Check the Java in BrewĪt the time of installing, the latest stable version is 15.0.2 $ brew info java Assuming you have installed Homebrew already, otherwise, you can go to the official website of homebrew and install it first, after that, use the following commands will help you install the latest Java (OpenJDK) in your Macġ.
