前提条件
Amazon Corretto 11 のインストール
$ brew cask install corretto
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 81, done.
remote: Counting objects: 100% (81/81), done.
remote: Compressing objects: 100% (74/74), done.
remote: Total 413960 (delta 39), reused 13 (delta 7), pack-reused 413879
Receiving objects: 100% (413960/413960), 188.59 MiB | 1.33 MiB/s, done.
Resolving deltas: 100% (292409/292409), done.
Tapped 1 command and 3536 casks (3,652 files, 202.3MB).
==> Downloading https://corretto.aws/downloads/resources/11.0.6.10.1/amazon-corretto-11.0.6.10.1-2-macosx-x64.pkg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'corretto'.
==> Installing Cask corretto
==> Creating Caskroom at /usr/local/Caskroom
==> We'll set permissions properly so we won't need sudo in the future.
Password:
==> Running installer for corretto; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
installer: Package name is Amazon Corretto 11
installer: Upgrading at base path /
installer: The upgrade was successful.
🍺 corretto was successfully installed!
Amazon Corretto 8 のインストール
古いバージョンも登録されているリポジトリを追加
$ brew tap homebrew/cask-versions
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
awscli@1 cacli gh katago libdeflate pueue
==> Updated Formulae
abcmidi conan groovysdk maven@3.2 procs
ace corral gsoap maven@3.3 profanity
agedu cppad haproxy maven@3.5 proj
akka crystal helm mesa proteinortho
allegro cython helm@2 metabase psqlodbc
angular-cli dar helmfile mgba pumba
ansible dartsim hevea micro pyinvoke
apache-arrow dateutils hlint minikube pympress
apache-arrow-glib deno homebank minio python-markdown
apache-ctakes dive http-parser mint qxmpp
apache-flink dmd hugo mk-configure repo
appstream-glib docker-completion i2p modules rex
arcade-learning-environment dovecot i386-elf-gdb movgrab riff
arduino-cli dvc icecream nano ruby-build
armadillo elixir imgproxy nats-streaming-server run
asymptote emscripten ioping navi rust
atlassian-cli erlang istioctl ncdu salt
ats2-postiats exploitdb jboss-forge nesc scons
avro-c eye-d3 jena nng sfk
avro-cpp fail2ban jenkins nnn sile
avro-tools fantom jhipster node-build simgrid
aws-cdk fauna-shell jsonnet node@12 simple-scan
aws-sdk-cpp fcl jsonschema2pojo now-cli sip
awscli fdclone kops nss skopeo
bash feh kubecfg ocp snakemake
beast findomain kubernetes-cli opa sphinx-doc
benthos fio kyma-cli openssh starship
bitrise fish lazygit openttd stress-ng
bmake fits ldns operator-sdk subnetcalc
broot fluent-bit ledger ott swiftlint
byacc flyway lftp packer sysdig
byobu folly libarchive paket terragrunt
caf freeswitch libcdr par2 texlab
cdogs-sdl fx libdap pcre tile38
cfn-lint gauge libfixbuf petsc tomcat
chakra gdb libgee petsc-complex tomcat@8
check_postgres gimme-aws-creds libgpg-error phpunit ttyd
checkbashisms gist libmtp picard-tools txr
cimg glooctl libphonenumber platformio v8
citus gmic libpqxx pod2man vala
ckan go libpsl postgresql verilator
clojure go@1.12 libtrace postgresql@10 wtf
clojurescript godep liquibase postgresql@11 xtensor
closure-compiler gosu lldpd postgresql@9.4 yq
cmake gradle lxc postgresql@9.5 zeek
cobalt groovy maven postgresql@9.6
==> Deleted Formulae
python@2
==> Tapping homebrew/cask-versions
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-versions'...
remote: Enumerating objects: 194, done.
remote: Counting objects: 100% (194/194), done.
remote: Compressing objects: 100% (189/189), done.
remote: Total 194 (delta 14), reused 44 (delta 2), pack-reused 0
Receiving objects: 100% (194/194), 84.67 KiB | 422.00 KiB/s, done.
Resolving deltas: 100% (14/14), done.
Tapped 163 casks (211 files, 334.9KB).
インストールする。
$ brew cask install corretto8
==> Downloading https://corretto.aws/downloads/resources/8.242.08.1/amazon-corretto-8.242.08.1-1-macosx-x64.pkg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'corretto8'.
==> Installing Cask corretto8
==> Running installer for corretto8; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
installer: Package name is Amazon Corretto 8
installer: Upgrading at base path /
installer: The upgrade was successful.
🍺 corretto8 was successfully installed!
anyenv を使って jenv をインストールする
$ anyenv install jenv
/var/folders/90/hcnfc9cn5dz9xtbjp3ndvl4h0000gn/T/jenv.20200215134045.48505 ~
Cloning https://github.com/gcuisinier/jenv.git master to jenv...
Cloning into 'jenv'...
remote: Enumerating objects: 35, done.
remote: Counting objects: 100% (35/35), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 1166 (delta 16), reused 5 (delta 1), pack-reused 1131
Receiving objects: 100% (1166/1166), 434.55 KiB | 665.00 KiB/s, done.
Resolving deltas: 100% (529/529), done.
~
Install jenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session.
profile をリロードする。
$ exec $SHELL -l
jenv に各種バージョンの JAVA_HOME を追加
現状の JAVA_HOME を確認
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
11.0.6, x86_64: "Amazon Corretto 11"/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
1.8.0_242, x86_64: "Amazon Corretto 8" /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home
ここで表示されている( /Library から始まっている)ディレクトリを直接記載してもいいのだが、せっかくコマンドが用意されているので、それを使って記載する。
$ jenv add $(/usr/libexec/java_home -v 11)
corretto64-11.0.6 added
11.0.6 added
11.0 added
11 added
$ jenv add $(/usr/libexec/java_home -v 1.8)
corretto64-1.8.0.242 added
1.8.0.242 added
1.8 added
jenv のバージョンを切り替える
現状はこうなっている。
$ jenv versions
* system (set by /Users/naoki/.anyenv/envs/jenv/version)
1.8
1.8.0.242
11
11.0
11.0.6
corretto64-1.8.0.242
corretto64-11.0.6
$ java -version
openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment Corretto-11.0.6.10.1 (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.6.10.1 (build 11.0.6+10-LTS, mixed mode)
global のバージョンを 1.8 系に変更する
$ jenv global 1.8
$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment Corretto-8.242.08.1 (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM Corretto-8.242.08.1 (build 25.242-b08, mixed mode)
global のバージョンを 11系に変更する
$ jenv global 11
$ java -version
openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment Corretto-11.0.6.10.1 (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.6.10.1 (build 11.0.6+10-LTS, mixed mode)
こんな感じで切り替えることができるようになった。