리눅스에 jdk 설치 


AWS에 아마 기본으로 있을껀데 혹시나 싶어서 확인


[root@ip-172-31-9-0 ~]# java -version

java version "1.7.0_151"

OpenJDK Runtime Environment (amzn-2.6.11.0.74.amzn1-x86_64 u151-b00)

OpenJDK 64-Bit Server VM (build 24.151-b00, mixed mode)


1.7이 있징ㅎㅎ (정~~~말 귀찮은 짓을 피하고 싶으면 기존에 있던거 삭제하자!!!)


근데 난 1.8을 쓰고 싶어서 yum으로 설치 할수 있는 jdk 확인

만약 없으면 직접 다운로드 받아서 설치해야한다.


[ec2-user@ip-172-31-9-0 ~]$ yum list java*jdk-devel

Loaded plugins: priorities, update-motd, upgrade-helper

Available Packages

java-1.6.0-openjdk-devel.x86_64    1:1.6.0.41-1.13.13.1.77.amzn1    amzn-main

java-1.7.0-openjdk-devel.x86_64    1:1.7.0.151-2.6.11.0.74.amzn1    amzn-main

java-1.8.0-openjdk-devel.x86_64    1:1.8.0.151-1.b12.35.amzn1       amzn-updates



jdk 1.8 설치 시작


[ec2-user@ip-172-31-9-0 ~]$ yum install java-1.8.0-openjdk-devel.x86_64

Loaded plugins: priorities, update-motd, upgrade-helper

You need to be root to perform this command.



하려 했지만 root에서 실행해야 한다고 하네..ㅎㅎ

설치 실패 메세지 : You need to be root to perform this command.


루트 권한으로 변경


[ec2-user@ip-172-31-9-0 ~]$ sudo su -

Last login: Wed Dec  6 02:17:50 UTC 2017 on pts/0

 


root 에서 jdk 1.8 설치 시작


[root@ip-172-31-9-0 ~]#  yum install java-1.8.0-openjdk-devel.x86_64

Loaded plugins: priorities, update-motd, upgrade-helper

amzn-main                                                | 2.1 kB     00:00

amzn-updates                                             | 2.5 kB     00:00

Resolving Dependencies

--> Running transaction check

---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.151-1.b12.35.amzn1 will be                       installed

--> Processing Dependency: java-1.8.0-openjdk(x86-64) = 1:1.8.0.151-1.b12.35.amz                      n1 for package: 1:java-1.8.0-openjdk-devel-1.8.0.151-1.b12.35.amzn1.x86_64

--> Processing Dependency: libawt_xawt.so(SUNWprivate_1.1)(64bit) for package: 1                      :java-1.8.0-openjdk-devel-1.8.0.151-1.b12.35.amzn1.x86_64

--> Processing Dependency: libawt_xawt.so()(64bit) for package: 1:java-1.8.0-ope                      njdk-devel-1.8.0.151-1.b12.35.amzn1.x86_64

--> Running transaction check

---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.151-1.b12.35.amzn1 will be instal                      led

--> Processing Dependency: java-1.8.0-openjdk-headless(x86-64) = 1:1.8.0.151-1.b                      12.35.amzn1 for package: 1:java-1.8.0-openjdk-1.8.0.151-1.b12.35.amzn1.x86_64

--> Running transaction check

---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.151-1.b12.35.amzn1 will                       be installed

amzn-main/latest/filelists_db                            | 5.7 MB     00:00

amzn-updates/latest/filelists_db                         | 1.9 MB     00:00

--> Processing Dependency: copy-jdk-configs >= 1.1-3 for package: 1:java-1.8.0-o                      penjdk-headless-1.8.0.151-1.b12.35.amzn1.x86_64

--> Processing Dependency: lksctp-tools(x86-64) for package: 1:java-1.8.0-openjd                      k-headless-1.8.0.151-1.b12.35.amzn1.x86_64

--> Running transaction check

---> Package copy-jdk-configs.noarch 0:1.2-1.2.amzn1 will be installed

---> Package lksctp-tools.x86_64 0:1.0.10-7.7.amzn1 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


================================================================================

 Package                   Arch   Version                    Repository    Size

================================================================================

Installing:

 java-1.8.0-openjdk-devel  x86_64 1:1.8.0.151-1.b12.35.amzn1 amzn-updates  12 M

Installing for dependencies:

 copy-jdk-configs          noarch 1.2-1.2.amzn1              amzn-main     13 k

 java-1.8.0-openjdk        x86_64 1:1.8.0.151-1.b12.35.amzn1 amzn-updates 244 k

 java-1.8.0-openjdk-headless

                           x86_64 1:1.8.0.151-1.b12.35.amzn1 amzn-updates  39 M

 lksctp-tools              x86_64 1.0.10-7.7.amzn1           amzn-main     89 k


Transaction Summary

================================================================================

Install  1 Package (+4 Dependent packages)


Total download size: 51 M

Installed size: 143 M

 


다운로드 가 완료 됐고 설치 하겠냐고 물어볼꺼야


그럼 y 입력하고 enter!


다운로드한 패키지 압축 풀고 설치 시작!

Is this ok [y/d/N]: y


Downloading packages:

(1/5): copy-jdk-configs-1.2-1.2.amzn1.noarch.rpm           |  13 kB   00:00

(2/5): java-1.8.0-openjdk-1.8.0.151-1.b12.35.amzn1.x86_64. | 244 kB   00:00

(3/5): lksctp-tools-1.0.10-7.7.amzn1.x86_64.rpm            |  89 kB   00:00

(4/5): java-1.8.0-openjdk-devel-1.8.0.151-1.b12.35.amzn1.x |  12 MB   00:01

(5/5): java-1.8.0-openjdk-headless-1.8.0.151-1.b12.35.amzn |  39 MB   00:02

--------------------------------------------------------------------------------

Total                                               16 MB/s |  51 MB  00:03

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : copy-jdk-configs-1.2-1.2.amzn1.noarch                        1/5

  Installing : lksctp-tools-1.0.10-7.7.amzn1.x86_64                         2/5

  Installing : 1:java-1.8.0-openjdk-devel-1.8.0.151-1.b12.35.amzn1.x86_64   3/5

  Installing : 1:java-1.8.0-openjdk-headless-1.8.0.151-1.b12.35.amzn1.x86   4/5

  Installing : 1:java-1.8.0-openjdk-1.8.0.151-1.b12.35.amzn1.x86_64         5/5

  Verifying  : lksctp-tools-1.0.10-7.7.amzn1.x86_64                         1/5

  Verifying  : copy-jdk-configs-1.2-1.2.amzn1.noarch                        2/5

  Verifying  : 1:java-1.8.0-openjdk-devel-1.8.0.151-1.b12.35.amzn1.x86_64   3/5

  Verifying  : 1:java-1.8.0-openjdk-1.8.0.151-1.b12.35.amzn1.x86_64         4/5

  Verifying  : 1:java-1.8.0-openjdk-headless-1.8.0.151-1.b12.35.amzn1.x86   5/5


Installed:

  java-1.8.0-openjdk-devel.x86_64 1:1.8.0.151-1.b12.35.amzn1


Dependency Installed:

  copy-jdk-configs.noarch 0:1.2-1.2.amzn1

  java-1.8.0-openjdk.x86_64 1:1.8.0.151-1.b12.35.amzn1

  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.151-1.b12.35.amzn1

  lksctp-tools.x86_64 0:1.0.10-7.7.amzn1


Complete!

 


완료!


설치된것 확인.. 


[root@ip-172-31-9-0 jvm]# javac -version

javac 1.8.0_151


------------------------------------------


설치된 디렉토리에 있는 jdk, jre..


[root@ip-172-31-9-0 jvm]# ll -ltr /usr/lib/jvm/

total 8

drwxr-xr-x 7 root root 4096 Oct 25 20:46 java-1.8.0-openjdk-1.8.0.151-1.b12.35.amzn1.x86_64

drwxr-xr-x 3 root root 4096 Nov 20 22:12 java-1.7.0-openjdk-1.7.0.151.x86_64

lrwxrwxrwx 1 root root   39 Nov 20 22:12 jre-1.7.0-openjdk.x86_64 -> java-1.7.0-openjdk-1.7.0.151.x86_64/jre

lrwxrwxrwx 1 root root   27 Nov 20 22:12 jre-1.7.0 -> /etc/alternatives/jre_1.7.0


오늘(12월 7일)에 설치된 jdk 1.8 버전


lrwxrwxrwx 1 root root   25 Dec  7 04:46 java-1.8.0-openjdk -> java-1.8.0-openjdk.x86_64

lrwxrwxrwx 1 root root   50 Dec  7 04:46 java-1.8.0-openjdk.x86_64 -> java-1.8.0-openjdk-1.8.0.151-1.b12.35.amzn1.x86_64

lrwxrwxrwx 1 root root   34 Dec  7 04:46 java-openjdk -> /etc/alternatives/java_sdk_openjdk

lrwxrwxrwx 1 root root   32 Dec  7 04:46 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0

lrwxrwxrwx 1 root root   26 Dec  7 04:46 java -> /etc/alternatives/java_sdk

lrwxrwxrwx 1 root root   54 Dec  7 04:46 jre-1.8.0-openjdk.x86_64 -> java-1.8.0-openjdk-1.8.0.151-1.b12.35.amzn1.x86_64/jre

lrwxrwxrwx 1 root root   24 Dec  7 04:46 jre-1.8.0-openjdk -> jre-1.8.0-openjdk.x86_64

lrwxrwxrwx 1 root root   29 Dec  7 04:46 jre-openjdk -> /etc/alternatives/jre_openjdk

lrwxrwxrwx 1 root root   27 Dec  7 04:46 jre-1.8.0 -> /etc/alternatives/jre_1.8.0

lrwxrwxrwx 1 root root   21 Dec  7 04:46 jre -> /etc/alternatives/jre

 


설치된거 확인 했으면 java 실행해봐야지

간단한 helloworld 작성해서 실행해 보자.


HelloWorld java 파일 생성

[root@ip-172-31-9-0 ~]# echo "public class HelloWorld {" > HelloWorld.java

[root@ip-172-31-9-0 ~]# echo "  public static void main(String[] args) {" >> HelloWorld.java

[root@ip-172-31-9-0 ~]# echo "    System.out.println(\"Hello, World\");" >> HelloWorld.java

[root@ip-172-31-9-0 ~]# echo "  }" >> HelloWorld.java

[root@ip-172-31-9-0 ~]# echo "}" >> HelloWorld.java

[root@ip-172-31-9-0 ~]# javac HelloWorld.java


컴파일된 class 파일 확인
[root@ip-172-31-9-0 ~]# ll
total 8
-rw-r--r-- 1 root root 426 Dec  7 05:45 HelloWorld.class
-rw-r--r-- 1 root root 115 Dec  7 05:45 HelloWorld.java

실행
[root@ip-172-31-9-0 ~]# java HelloWorld

에러 똿!!!!!!!!!!!
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:312)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)



javac와 java가 바라보는게 달라.. 그래서 컴파일은 1.8로 됐는데 실행은 1.7로 실행이 되는거지..


JAVA_HOME 설정 변경해주는건 아래 링크에서 확인하자.

http://carfediem-is.tistory.com/6


설정 변경하고 javac와 java가 일치하면 이렇게 정상적으로 실행이 되지


HelloWorld 실행 결과

Hello, World

 


이제 jdk 설치 했으니까 was 설정해보자

'Develope > Server' 카테고리의 다른 글

JBOSS 7.1.1 설치 및 실행  (0) 2017.12.08
NGINX 기동 및 확인  (0) 2017.12.08
NGINX 설치  (0) 2017.12.08
리눅스 JAVA 버전 확인 및 변경  (0) 2017.12.07
리눅스 종류, 버전 확인  (0) 2017.12.07

+ Recent posts