I googling a while for "how to install java 8 on macOS" but isn't help me so much to figure it out how to actually install java 8 in my MacBook. Some tutorial is outdated. So I decided to write a tutorial for setup java development environment in macOS which covering all of you need to setup and how to have multiple versions of java in the same machine, how to switch java version 8 to 13, etc.
Let's get started.
Open terminal or iTerm and paste this line to install brew.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew tap adoptopenjdk/openjdk # javc 8 $ brew cask install adoptopenjdk8 # java 11 $ brew cask install adoptopenjdk11 # gradle $ brew install gradle # maven $ brew install maven
If you want to use other versions of java in the same machine, instead of setup
JAVA_HOME every time that you started the terminal we'll use
jenv for switching between versions and do the path setup for you.
$ brew install jenv
Add java home folder to jenv
$ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home $ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
➜ ~ jenv jenv 0.5.2 Usage: jenv <command> [<args>] Some useful jenv commands are: commands List all available jenv commands local Set or show the local application-specific Java version global Set or show the global Java version shell Set or show the shell-specific Java version rehash Rehash jenv shims (run this after installing executables) version Show the current Java version and its origin versions List all Java versions available to jenv which Display the full path to an executable whence List all Java versions that contain the given executable See `jenv help <command>' for information on a specific command. For full documentation, see: https://github.com/hikage/jenv#readme
list versions with
➜ ~ jenv versions * system (set by /Users/<USER>/.jenv/version) 1.8 188.8.131.52 11.0 11.0.4 openjdk64-184.108.40.206 openjdk64-11.0.4
switching between version
jenv shell openjdk64-220.127.116.11 #or openjdk64-11.0.4
➜ ~ 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) ➜ ~ jenv versions system 1.8 18.104.22.168 11.0 11.0.4 * openjdk64-22.214.171.124 (set by JENV_VERSION environment variable) openjdk64-11.0.4 ➜ ~ jenv shell openjdk64-11.0.4 ➜ ~ java -version openjdk version "11.0.4" 2019-07-16 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode) ➜ ~ jenv versions system 1.8 126.96.36.199 11.0 11.0.4 openjdk64-188.8.131.52 * openjdk64-11.0.4 (set by JENV_VERSION environment variable)
Set default java version in
/Users/<USER>/.jenv/version and the content will be the version of java you wanna use, save file and start a new shell will be set default java version that you wrote in file.
➜ ~ jenv versions system 1.8 184.108.40.206 11.0 11.0.4 * openjdk64-220.127.116.11 (set by /Users/ayuth/.jenv/version) openjdk64-11.0.4
P.S. Oh one thing, if you can make a cover image more good than me please don't hesitate to send me it. I just make this image for save my life.