개요
- 프로젝트 별 여러개의 Java 버전을 사용중이다. 그래서 jenv 를 이용하여 여러개의 자바 버전을 관리하여야 한다.
설치 및 가이드
1. jenv 설치
% brew install jenv
2. ~/.zshrc 설정
% echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
% echo 'eval "$(jenv init -)"' >> ~/.zshrc
source ~/.zshrc
3. jenv Export Plugin 설정
% jenv enable-plugin export
4. jenv 정상 설치 확인
% jenv
jenv 0.5.6
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"
See `jenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/jenv/jenv/blob/master/README.md
5. Java 설치
% brew search jdk
==> **Formulae**
openjdk openjdk@11 openjdk@17 openjdk@8 jd mdk cdk
==> **Casks**
adoptopenjdk graalvm-jdk microsoft-openjdk oracle-jdk-javadoc semeru-jdk-open
gama-jdk jdk-mission-control oracle-jdk sapmachine-jdk
% brew install openjdk@11
% brew install openjdk@17
6. Symbolic Link 설정
% sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
% sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk
% ls /Library/Java/JavaVirtualMachines
openjdk-11.jdk openjdk-17.jdk
7. jenv 에 설치한 JDK 등록
% jenv add /Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home/
**openjdk64-11.0.21 added**
**11.0.21 added**
**11.0 added**
**11.0.21 already present, skip installation**
% jenv add /Library/Java/JavaVirtualMachines/openjdk-17.jdk/Contents/Home/
**openjdk64-17.0.9 added**
**17.0.9 added**
**17.0 added**
**17.0.9 already present, skip installation**
8. Jave 버전 확인 및 설정
% jenv versions
* system (set by /Users/dobby/.jenv/version)
11.0
11.0.21
17.0
17.0.9
openjdk64-11.0.21
openjdk64-17.0.9
% jenv global {JAVA_VERSION}
% jenv local {JAVA_VERSION}
% java -version
참고 링크 : https://velog.io/@geun/Setting-jenv%EB%A1%9C-%EC%97%AC%EB%9F%AC-Java-%EB%B2%84%EC%A0%84-%EC%82%AC%EC%9A%A9%EA%B4%80%EB%A6%AC%ED%95%98%EA%B8%B0-For-Mac-g20bsd7e