환경설정
Jenv 설치 및 세팅
IT찬니
2022. 1. 23. 16:04
- 다양한 JDK 버전을 관리하기 위함
- 유사한 툴로 pyenv, nvm 등이 있음
# [NOTICE!!]
# 1) DO NOT append $JAVA_HOME/bin to PATH manually
# jenv uses own shell scripts in $JENV/shims directory instead
# 2) jenv cannot distinguish same version between different distro
# e.g. openjdk-8 == adoptjdk-8 == oraclejdk-8
# So, recommend you to use multiple versions with same distro
# 1. Install
# use `brew install jenv` on MacOS
git clone https://github.com/jenv/jenv.git $HOME/.jenv
# 2. Configure
echo -e "\n# [jenv]" >> ~/.bashrc
echo 'export JENV_ROOT="$HOME/.jenv"' >> ~/.bashrc
echo 'export PATH="$JENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(jenv init -)"' >> ~/.bashrc
source ~/.bashrc
mkdir -p $JENV_ROOT/versions # to use 'jenv add <JAVA_HOME>' without error: No such file or directory
jenv enable-plugin export # to automatically assign $JAVA_HOME every version changes (USE ONCE!!)
# 3. JDK Install
apt update && apt install -y software-properties-common
apt-add-repository 'deb http://security.debian.org/debian-security stretch/updates main'
apt update && apt install -y openjdk-8-jdk openjdk-11-jdk
# 4. Add JAVA_HOME to jenv
# e.g. jenv add /usr/lib/jvm/java-8-openjdk-amd64
# e.g. jenv add /usr/lib/jvm/java-11-openjdk-amd64
jenv add <JAVA_HOME_PATH>
jenv versions
jenv global <GLOBAL_JAVA_VERSION>
jenv local <LOCAL_JAVA_VERSION>
echo $JAVA_HOME # <CURRENT_JAVA_VERSION>