CentOS JDK 설치

Jmnote (토론 | 기여)님의 2016년 9월 21일 (수) 17:13 판 (→‎설치 확인)
  다른 뜻에 대해서는 윈도우 JDK 설치 문서를 참조하십시오.
리눅스 JDK 설치

1 개요

  • 리눅스에서도[1] JDK와 JRE는 별도의 패키지이다.
java-버전-openjdk 패키지가 JRE,
java-버전-openjdk-devel 패키지가 JDK라고 생각하면 된다.
  • JDK가 JRE에 의존성이 있다.[2]
yum으로 JDK를 설치하라고 하면 JRE를 먼저 설치한다.

2 설치 확인

3 설치가능 확인

[root@zetawiki ~]# yum list java*jdk-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
java-1.6.0-openjdk-devel.x86_64             1:1.6.0.40-1.13.12.6.el6_8              updates
java-1.7.0-openjdk-devel.x86_64             1:1.7.0.111-2.6.7.2.el6_8               updates
java-1.8.0-openjdk-devel.x86_64             1:1.8.0.101-3.b13.el6_8                 updates
→ 1.6, 1.7, 1.8 버전이 설치 가능하다.
→ 여기서는 1.8 버전을 설치한다.

4 설치

[root@zetawiki ~]# yum install java-1.8.0-openjdk-devel.x86_64
... (생략)
===========================================================================================
 Package                         Arch       Version                      Repository   Size
===========================================================================================
Installing:
 java-1.8.0-openjdk-devel        x86_64     1:1.8.0.101-3.b13.el6_8      updates      10 M
Updating:
 libxcb                          x86_64     1.11-2.el6                   base        142 k
Installing for dependencies:
 alsa-lib                        x86_64     1.1.0-4.el6                  base        389 k
 giflib                          x86_64     4.1.6-3.1.el6                base         37 k
 java-1.8.0-openjdk              x86_64     1:1.8.0.101-3.b13.el6_8      updates     197 k
 java-1.8.0-openjdk-headless     x86_64     1:1.8.0.101-3.b13.el6_8      updates      32 M
 jpackage-utils                  noarch     1.7.5-3.16.el6               base         60 k
 libICE                          x86_64     1.0.6-1.el6                  base         53 k
 libSM                           x86_64     1.2.1-2.el6                  base         37 k
 libXfont                        x86_64     1.5.1-2.el6                  base        145 k
 libXtst                         x86_64     1.2.2-2.1.el6                base         19 k
 libfontenc                      x86_64     1.1.2-3.el6                  base         29 k
 pkgconfig                       x86_64     1:0.23-9.1.el6               base         70 k
 ttmkfdir                        x86_64     3.0.9-32.1.el6               base         43 k
 tzdata-java                     noarch     2016f-1.el6                  updates     180 k
 xorg-x11-font-utils             x86_64     1:7.2-11.el6                 base         75 k
 xorg-x11-fonts-Type1            noarch     7.2-11.el6                   base        520 k
Updating for dependencies:
 libX11                          x86_64     1.6.3-2.el6                  base        586 k
 libX11-common                   noarch     1.6.3-2.el6                  base        169 k

Transaction Summary
===========================================================================================
Install      16 Package(s)
Upgrade       3 Package(s)

Total download size: 45 M
Is this ok [y/N]: y
... (생략)
Installed:
  java-1.8.0-openjdk-devel.x86_64 1:1.8.0.101-3.b13.el6_8                                  

Dependency Installed:
  alsa-lib.x86_64 0:1.1.0-4.el6                                                            
  giflib.x86_64 0:4.1.6-3.1.el6                                                            
  java-1.8.0-openjdk.x86_64 1:1.8.0.101-3.b13.el6_8                                        
  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.101-3.b13.el6_8                               
  jpackage-utils.noarch 0:1.7.5-3.16.el6                                                   
  libICE.x86_64 0:1.0.6-1.el6                                                              
  libSM.x86_64 0:1.2.1-2.el6                                                               
  libXfont.x86_64 0:1.5.1-2.el6                                                            
  libXtst.x86_64 0:1.2.2-2.1.el6                                                           
  libfontenc.x86_64 0:1.1.2-3.el6                                                          
  pkgconfig.x86_64 1:0.23-9.1.el6                                                          
  ttmkfdir.x86_64 0:3.0.9-32.1.el6                                                         
  tzdata-java.noarch 0:2016f-1.el6                                                         
  xorg-x11-font-utils.x86_64 1:7.2-11.el6                                                  
  xorg-x11-fonts-Type1.noarch 0:7.2-11.el6                                                 

Updated:
  libxcb.x86_64 0:1.11-2.el6                                                               

Dependency Updated:
  libX11.x86_64 0:1.6.3-2.el6              libX11-common.noarch 0:1.6.3-2.el6             

Complete!

5 설치 확인

[root@zetawiki ~]# rpm -qa java*jdk-devel
java-1.8.0-openjdk-devel-1.8.0.101-3.b13.el6_8.x86_64
[root@zetawiki ~]# javac -version
javac 1.8.0_101

6 Hello world 테스트

명령어
echo "public class HelloWorld {" > HelloWorld.java
echo "  public static void main(String[] args) {" >> HelloWorld.java
echo "    System.out.println(\"Hello, World\");" >> HelloWorld.java
echo "  }" >> HelloWorld.java
echo "}" >> HelloWorld.java
javac HelloWorld.java
java HelloWorld
rm -f HelloWorld.java HelloWorld.class
예시
[root@zetawiki ~]# echo "public class HelloWorld {" > HelloWorld.java
[root@zetawiki ~]# echo "  public static void main(String[] args) {" >> HelloWorld.java
[root@zetawiki ~]# echo "    System.out.println(\"Hello, World\");" >> HelloWorld.java
[root@zetawiki ~]# echo "  }" >> HelloWorld.java
[root@zetawiki ~]# echo "}" >> HelloWorld.java
[root@zetawiki ~]# javac HelloWorld.java
[root@zetawiki ~]# java HelloWorld
Hello, World
[root@zetawiki ~]# rm -f HelloWorld.java HelloWorld.class

7 같이 보기

8 주석

  1. 윈도우와 마찬가지로
  2. 따라서 JDK만 설치할 수는 없다.
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}