1. 실습_Java 환경설정
다양한 프로젝트를 동시에 개발을 하는 경우가 있습니다. 각 프로젝트 마다 사용하는 자바 버전이 다를 수가 있습니다. 이 모든 자바 버전들이 동시에 컴퓨터에 설치가 되어있어야 하고, 자바 버전을 바꿔가면서 개발을 할 수 있어야 합니다. 이럴 때 어떻게 핸들링하는지 알아봅니다.
temurin
brew search temurin
==> Formulae
maturin
==> Casks
temurin ✔ temurin@11 ✔ temurin@17 temurin@19
temurin@20 temurin@21 temurin@8 ✔
# 설치
brew install --cask temurin@8
brew install --cask temurin@11
brew install --cask temurin@17
brew install --cask temurin@21
📚 주로 많이 사용되는 자바 버전은 8, 11, 17, 21 버전입니다.
자바가 설치된 위치 확인
/usr/libexec/java_home -V
자바 버전 확인
java -version
jenv 설치하기
brew update
brew install jenv
jenv 위치 환경변수 등록
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc
jenv의 Export Plugin 설치
$ jenv enable-plugin export
jenv 설치 확인
$ jenv
jenv 0.5.7
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
add Add JDK into jenv. A alias name will be generated by parsing "java -version"
remove Remove JDK installations
See `jenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/jenv/jenv/blob/master/README.md
jenv 활용하기
# 현재 설치된 자바 확인
ls /Library/Java/JavaVirtualMachines
# jenv 에 자바 추가하기
jenv add /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home/
jenv add /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/
# jenv 에 자바 제거하기
jenv remove /Library/Java/JavaVirtualMachines/openjdk64-11.0.24/Contents/Home/
# 확인
jenv versions
# jenv로 버전 변경하기
$ jenv global {JAVA_VERSION}
$ jenv local {JAVA_VERSION}
TIPS
java -version 명령어를 실행하면 macOS는 JDK를 /Library/Java/JavaVirtualMachines/ 에서 찾습니다.
homebrew로 설치한 JDK는 다른 위치에 저장됩니다.
homebrew로 설치한 파일아 저장되는 위치는 아래와 같습니다.
M1 Mac: /opt/homebrew/Cellar
Intel Mac: /usr/local/Cellar
또한 위 경로에 설치된 파일들은 /opt/homebrew/opt에 soft-link를 생성합니다.
OpenJDK를 설치하는 방법
brew search jdk
openjdk openjdk@11 ✔ openjdk@17 openjdk@21 openjdk@8 jd
mdk cdk
# 설치하기
brew install openjdk@11
brew install openjdk@17
📚 openJDK 8설치는 Apple Silicon Chip 환경에서 설치 오류가 발생합니다.
이 부분은 나중에 알아보도록 합니다.
Last updated