This article is for those who are worried about ** Java installation method ** and ** version to install ** on Mac.
There are three versions of Java, 8, 11 and 14.
"8 is fine now, but you may want to make it 14 in the future ~"
When you think about it, you're wondering which version to install.
After investigating, I found that homebrew-cask-versions can be used to manage multiple versions.
OS: macOS Catalina (version 10.15.4) Terminal: iTerm2
$ brew -v
If the version is not displayed, it is installed.
$ brew update
The command to install is described on Official site. You can install it by copying it, pasting it into the terminal, and executing it.
Described commands as of May 09, 2020
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
It is a function that manages multiple versions.
Execute the installation command described on the Official Site. Described commands as of May 09, 2020
$ brew tap homebrew/cask-versions
It's more like a Homebrew extension than an installation.
The latest version as of May 09, 2020 is Java 14, so without versioning Java 14 will be installed when you install it.
$ brew cask install java
$ brew cask install java11
$ brew cask install java8
Error: Cask 'java8' is unavailable: No Cask with this name exists.
-> Error occurs. It seems that an error occurs due to the license.
Install "adoptopenjdk8" which is prepared as an alternative.
$ brew cask install homebrew/cask-versions/adoptopenjdk8
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
14.0.1, x86_64: "OpenJDK 14.0.1" /Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home
11.0.2, x86_64: "OpenJDK 11.0.2" /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home
1.8.0_252, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home
Update the configuration file that is loaded when the shell you are using starts up.
By default, a shell called bash is used, I think the configuration file is a file called "~ / .bashrc".
Add it to the two environment variables "JAVA_HOME" and "PATH".
Please write one of the following three according to the version you want to use.
Java14
export JAVA_HOME=`/usr/libexec/java_home -v "14"`
PATH=${JAVA_HOME}/bin:${PATH}
Java11
export JAVA_HOME=`/usr/libexec/java_home -v "11"`
PATH=${JAVA_HOME}/bin:${PATH}
Java8
export JAVA_HOME=`/usr/libexec/java_home -v "1.8"`
PATH=${JAVA_HOME}/bin:${PATH}
After writing, launch a new terminal application Check the Java version.
$ java --version
/usr/libexec/java_home -V
Check the path of each version of Java using
In the Visual Studio Code settings [⌘ +,], If you search for "java home", the configuration file will be opened.
Specify the path of the current Java version in "java.home".
Example:
"java.home": "/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home"
That's the "how to switch between multiple versions of Java using Homebrew on a Mac" that I researched.
I would be grateful if you could let me know if there are any strange points or better ways.
After the installation, I would like to write a program or debug it.
I also wrote an article about building a development environment in Java (writing a program or executing debug), so please refer to it if you like.
-Java Development Environment (Mac, VS Code) -Java Development Environment (Mac, Eclipse)
end.
Recommended Posts