DEV/JAVA

jevn 설정 (JDK 버전 변경하기)

행운개발자 2024. 1. 26. 21:47
728x90

1. jenv 설치

brew install jenv

 

2. jdk 설치

  • brew tap AdoptOpenJDK/openjdk
  • brew install --cask adoptopenjdk8
  • brew install --cask adoptopenjdk11

아래와 같은 에러가 발생하는 경우에는

hwanseok@hwanseoks-MacBook-Pro ~ % brew install --cask adoptopenjdk8
Error: Cask adoptopenjdk8 exists in multiple taps:
  homebrew/cask-versions/adoptopenjdk8
  adoptopenjdk/openjdk/adoptopenjdk8

 

아래의untap을 해준 뒤 다시 install을 하면 된다

brew untap adoptopenjdk/openjdk

 

 

3. jenv 터미널 설정 (~/.zshrc)

export PATH="$HOME/.jenv/bin:$PATH" 
eval "$(jenv init -)" 

# Elastic Search Java Home
ES_JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home export ES_JAVA_HOME

 

4.jenv에 jdk 추가

  • jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
  • jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
  • jenv add /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home (jdk17 버전은 경로가 다르니 확인해보기)

 

5. jenv global 설정 / local 설정

  1. jenv global {VERSION}
  2. jenv local {VERSION}

 

6. jenv 설정 확인

  1. jenv global
  2. jenv local

728x90