How to Install Java on MacOS - RLidea/dev.docs GitHub Wiki

How to Install Java on MacOS

Step 1. Install Homebrew

Link : Homebrew

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Step 2. Install Java

Link : AdoptOpenJDK

# Latest
$ brew cask install adoptopenjdk

# Other Versions
$ brew tap AdoptOpenJDK/openjdk
$ brew cask install adoptopenjdk11
  • jEnv를 사용할 것이므로 homebrew의 path 설정 안내는 무시

Step 3. jEnv

Link : jEnv

1. Install jEnv

$ brew install jenv

# Shell
$ 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

2. jEnv Setting

$ jenv add Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
$ jenv global openjdk64-11.0.6

$ jenv versions
  system
  11.0
  11.0.6
* openjdk64-11.0.6 (set by /Users/user/.jenv/version)

3. JAVA_HOME Setting

$ jenv enable-plugin export
$ exec $SHELL -l

$ echo ${JAVA_HOME}
  /Users/user/.jenv/versions/openjdk64-11.0.6
$ java --version   
  openjdk 11.0.6 2020-01-14
  OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)
  OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)

Step 4. Install Maven/Gradle

# Maven
$ brew install maven
$ mvn --version

# Gradle
$ brew install Gradle
$ gradle --version
  • maven과 gradle의 dependency로 openjdk가 설치되지만 adoptopenjdk를 사용할 것이므로 무시
⚠️ **GitHub.com Fallback** ⚠️