#1. 설치 가능한 자바 버전 확인
sudo yum list | grep jdk
#2. openjdk 1.7.0 && 1.8.0 64비트 버전 설치
sudo yum install -y java-1.7.0-openjdk.x86_64 java-1.7.0-openjdk-devel.x86_64
sudo yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
#3. java 버전 확인
java -version
---
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)
---
#4. 설치된 java 위치 확인
which java
/usr/bin/java
/usr/bin
경로에 java가 실행파일로 운영이 되고 있다.# java 설치내용 확인
# ls -al 은 숨김파일을 포함한 모든 파일에 대한 상세 리스트를 요청하는 명령
# ls -al | grep java = ls -al 내용 중 'java' 내용만 출력을 요청하는 명령
cd usr/bin/
ls -al | grep java
lrwxrwxrwx 1 root root 26 Aug 21 03:12 alt-java -> /etc/alternatives/alt-java
lrwxrwxrwx 1 root root 22 Aug 21 03:12 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 Aug 21 15:29 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 25 Aug 21 15:29 javadoc -> /etc/alternatives/javadoc
lrwxrwxrwx 1 root root 23 Aug 21 15:29 javah -> /etc/alternatives/javah
lrwxrwxrwx 1 root root 23 Aug 21 15:29 javap -> /etc/alternatives/javap
/usr/bin/java
가 /etc/alternatives/...
를 가르키는 것을 볼 수 있다.alternatives
라는 명령어이다.업무적으로 JDK 버전을 바꾸어 줘야하는 상황이 오면 일일히 $JAVA_HOME
, java, javac, javadoc, jar … 등 손이 가는 데가 많다.
cd /usr/bin
ls -al | grep java
lrwxrwxrwx 1 root root 22 Aug 21 03:12 java -> /etc/alternatives/java
cd /etc/alternatives/
ls -al | grep java
lrwxrwxrwx 1 root root 77 Aug 21 03:12 java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.amzn2.0.1.x86_64/jre/bin/java
cd /usr/lib/jvm
ls -al
total 8
drwxr-xr-x 4 root root 4096 Aug 21 15:29 .
dr-xr-xr-x 35 root root 4096 Aug 21 03:12 ..
lrwxrwxrwx 1 root root 26 Aug 21 15:29 java -> /etc/alternatives/java_sdk
lrwxrwxrwx 1 root root 32 Aug 21 15:29 java-1.7.0 -> /etc/alternatives/java_sdk_1.7.0
lrwxrwxrwx 1 root root 40 Aug 21 15:29 java-1.7.0-openjdk -> /etc/alternatives/java_sdk_1.7.0_openjdk
drwxr-xr-x 8 root root 151 Aug 21 15:29 java-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.1.x86_64
lrwxrwxrwx 1 root root 32 Aug 21 02:04 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0
lrwxrwxrwx 1 root root 40 Aug 21 02:04 java-1.8.0-openjdk -> /etc/alternatives/java_sdk_1.8.0_openjdk
drwxr-xr-x 7 root root 135 Aug 21 02:04 java-1.8.0-openjdk-1.8.0.302.b08-0.amzn2.0.1.x86_64
lrwxrwxrwx 1 root root 34 Aug 21 15:29 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx 1 root root 21 Aug 21 03:12 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 27 Aug 21 03:12 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx 1 root root 35 Aug 21 03:12 jre-1.7.0-openjdk -> /etc/alternatives/jre_1.7.0_openjdk
lrwxrwxrwx 1 root root 58 Aug 21 03:12 jre-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.1.x86_64 -> java-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.1.x86_64/jre
lrwxrwxrwx 1 root root 27 Aug 21 02:03 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root 35 Aug 21 02:03 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx 1 root root 55 Aug 21 02:03 jre-1.8.0-openjdk-1.8.0.302.b08-0.amzn2.0.1.x86_64 -> java-1.8.0-openjdk-1.8.0.302.b08-0.amzn2.0.1.x86_64/jre
lrwxrwxrwx 1 root root 29 Aug 21 03:12 jre-openjdk -> /etc/alternatives/jre_openjdk
yum 방식으로 openjdk를 설치시 /usr/lib/jvm
폴더에 설치되어 있음을 확인할 수 있다.
이를 alternatives
명령어로 java 버전을 바꾸어 보자
# alternatives 내용을 살펴보자.
alternatives --help
----
alternatives version 1.7.4 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
usage: alternatives --install <link> <name> <path> <priority>
[--initscript <service>]
[--family <family>]
[--slave <link> <name> <path>]*
alternatives --remove <name> <path>
alternatives --auto <name>
alternatives --config <name>
alternatives --display <name>
alternatives --set <name> <path>
alternatives --list
common options: --verbose --test --help --usage --version --keep-missing
--altdir <directory> --admindir <directory>
----
#--config 옵션 활용
# openjdk-1.7.0 버전으로 바꾸어보자.
[root@localhost jvm]# alternatives --config java
----
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.amzn2.0.1.x86_64/jre/bin/java)
2 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.1.x86_64/jre/bin/java)
Enter to keep the current selection[+], or type selection number: 2
----
**# java 버전 확인**
[root@localhost jvm]# java -version
java version "1.7.0_261"
OpenJDK Runtime Environment (rhel-2.6.22.2.amzn2.0.1-x86_64 u261-b02)
OpenJDK 64-Bit Server VM (build 24.261-b02, mixed mode)
이후
/etc/profile
이나 / .bash_profile
에서 $JAVA_HOME
을 새로 설정# 환경변수 편집
vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.1.x86_64/
export PATH=$PATH:$JAVA_HOME
# 변경내역 저장
source /etc/profile
javac
방금과 같은 과정으로 반복