리눅스서버/Ubuntu

[Ubuntu] Java 여러개의 버전 설치 및 선택하기

http://portfolio.wonpaper.net 2023. 12. 26. 23:53

 

Ubuntu 20.04 

 

우분투에서 여러 버전의 Java jdk 를 다양하게 선택하고 그때그때 내가 원하는 버전으로 선택하도록 해보자.

 

설치되어 있는 Java  버전 확인하기

update-alternatives --list java

 

특정 Java 버전 설치하기

sudo apt install openjdk-8-jdk
sudo apt install openjdk-11-jdk
sudo apt install openjdk-17-jdk

 

원하는 Java 버전으로 선택하기

sudo update-alternatives --config java
sudo update-alternatives --config javac

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
root@lee-ubuntu:~# update-alternatives --list java
 
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
 
root@lee-ubuntu:~# sudo apt install openjdk-17-jdk
 
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
The following additional packages will be installed:
  openjdk-17-jdk-headless openjdk-17-jre openjdk-17-jre-headless
제안하는 패키지:
  openjdk-17-demo openjdk-17-source visualvm fonts-ipafont-gothic fonts-ipafont-mincho
  fonts-wqy-microhei | fonts-wqy-zenhei
 
root@lee-ubuntu:~# update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-17-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
 
 
root@lee-ubuntu:~# java -version
openjdk version "11.0.21" 2023-10-17
OpenJDK Runtime Environment (build 11.0.21+9-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.21+9-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)
 
 
root@lee-ubuntu:~# sudo update-alternatives --config java
대체 항목 java에 대해 (/usr/bin/java 제공) 3개 선택이 있습니다.
 
  선택       경로                                          우선순▒ 상태
------------------------------------------------------------
  0            /usr/lib/jvm/java-17-openjdk-amd64/bin/java      1711      자동 모드
* 1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      수동 모드
  2            /usr/lib/jvm/java-17-openjdk-amd64/bin/java      1711      수동 모드
  3            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      수동 모드
 
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-17-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode
root@lee-ubuntu:~# sudo update-alternatives --config javac
대체 항목 javac에 대해 (/usr/bin/javac 제공) 3개 선택이 있습니다.
 
  선택       경로                                        우선순▒ 상태
------------------------------------------------------------
* 0            /usr/lib/jvm/java-17-openjdk-amd64/bin/javac   1711      자동 모드
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/javac   1111      수동 모드
  2            /usr/lib/jvm/java-17-openjdk-amd64/bin/javac   1711      수동 모드
  3            /usr/lib/jvm/java-8-openjdk-amd64/bin/javac    1081      수동 모드
 
Press <enter> to keep the current choice[*], or type selection number: 2
 
root@lee-ubuntu:~# java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-120.04, mixed mode, sharing)
 
cs

 

 

참고 : https://mech2cs.tistory.com/entry/Ubuntu-2004-%EC%9E%90%EB%B0%94-JDK-%EC%84%A4%EC%B9%98-%EB%B0%8F-%EB%B2%84%EC%A0%84-%EA%B4%80%EB%A6%AC