--See Homebrew site - https://brew.sh
homebrew-cask-versions
$ brew tap homebrew/cask-versions
--Java installed by cask install java
will be the latest version (currently Java SE 14).
$ brew cask install java
$ brew cask install java11
--__ Not available due to license. AdoptOpenJDK, Corretto, [Zulu](https://jp.azul.com/downloads/ Substitute with zulu /) etc. __ -The SDK included differs depending on the JDK, so be careful.
$ brew cask install java8
$ brew cask install adoptopenjdk8
$ brew cask install corretto8
$ brew cask install zulu8
JAVA_HOME
)--/ usr / libexec / java_home
command
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
12.0.1, x86_64: "OpenJDK 12.0.1" /Library/Java/JavaVirtualMachines/openjdk-12.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_212, x86_64: "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk/Contents/Home
$ /usr/libexec/java_home --help
Usage: java_home [options...]
Returns the path to a Java home directory from the current user's settings.
Options:
[-v/--version <version>] Filter Java versions in the "JVMVersion" form 1.X(+ or *).
[-a/--arch <architecture>] Filter JVMs matching architecture (i386, x86_64, etc).
[-d/--datamodel <datamodel>] Filter JVMs capable of -d32 or -d64
[-t/--task <task>] Use the JVM list for a specific task (Applets, WebStart, BundledApp, JNI, or CommandLine)
[-F/--failfast] Fail when filters return no JVMs, do not continue with default.
[ --exec <command> ...] Execute the $JAVA_HOME/bin/<command> with the remaining arguments.
[-R/--request] Request installation of a Java Runtime if not installed.
[-X/--xml] Print full JVM list and additional data as XML plist.
[-V/--verbose] Print full JVM list with architectures.
[-h/--help] This usage information.
--Switch Java version on OS X
--Set the environment variable JAVA_HOME
using the java_home
command.
--Add to the .bashrc
and .zshrc
files according to the shell you are using.
Java SE 14
$ export JAVA_HOME=`/usr/libexec/java_home -v "14"`
$ PATH=${JAVA_HOME}/bin:${PATH}
Java SE 11
$ export JAVA_HOME=`/usr/libexec/java_home -v "11"`
$ PATH=${JAVA_HOME}/bin:${PATH}
Java SE 8
$ export JAVA_HOME=`/usr/libexec/java_home -v "1.8"`
$ PATH=${JAVA_HOME}/bin:${PATH}
--By introducing jEnv, it becomes easy to switch Java versions. --Reference: https://github.com/jenv/jenv
--Install with Homebrew
$ brew install jenv
--Set PATH
--Note that it depends on the shell used.
# Shell: bash
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
# Shell: zsh
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc
--Create a directory
$ cd ~
$ mkdir ~/.jenv/versions
--Install the JDK with Homebrew Cask. --Add the installed JDK to jEnv.
Addition of Java 8
$ jenv add `/usr/libexec/java_home -v "1.8"`
--The JDK with *
at the beginning is enabled.
$ jenv versions
* system (set by /Users/[User name]/.jenv/version)
1.8
1.8.0.222
openjdk64-1.8.0.222
--You can switch to any version output by jenv versions
.
$ jenv global 1.8.0.222
$ jenv versions
system
1.8
* 1.8.0.222 (set by /Users/[User name]/.jenv/version)
openjdk64-1.8.0.222
$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.222-b10, mixed mode)
--Applies only to specific directories.
--A .java-version
file will be created in the directory where you executed the command, and the specified version of the JDK will be available.
$ jenv local 11.0
$ jenv versions ✘
system
1.8
1.8.0.222
* 11.0 (set by /Users/[Directory where jenv local was executed]/.java-version)
11.0.2
openjdk64-1.8.0.222
openjdk64-11.0.2
$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
$ cat .java-version
11.0
JAVA_HOME
--To set JAVA_HOME
automatically, execute ʻenable-plugin export. --Execute
disable-plugin export` to cancel the automatic setting.
$ jenv enable-plugin export
Recommended Posts