Help us understand the problem. What is going on with this article?

AWS Cloud9でJava8開発環境を構築

More than 1 year has passed since last update.

はじめに

AWS Cloud9導入編はこちら
https://qiita.com/tu-kun/items/d7b4f1fa19cc93bc5b75

対象

  • AWS Cloud9でJava8にバージョンアップしたい人
  • よく分からないけどJava8を導入したい人

バージョンの確認方法

Java

$ java -version
java version "1.7.0_181"
OpenJDK Runtime Environment (amzn-x.x.xx.x.xx.amzn1-x86_64 u181-b00)
OpenJDK 64-Bit Server VM (build xx.xxx-b00, mixed mode)

Javac

$ javac -version
javac 1.7.0_181

パッケージの確認

java8のパッケージはjava-1.8.0-openjdk-develです。
こちらは開発者向けOpenJDKも一緒にインストールされるパッケージとなります。

$ yum search java-1.8.0-openjdk-devel
Loaded plugins: priorities, update-motd, upgrade-helper
epel                                                                                                                 12509/12509
1045 packages excluded due to repository priority protections
================================================ N/S matched: java-1.8.0-openjdk ================================================
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in single archive
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle

パッケージの導入

yum installはrootユーザーで実行しないといけないため、sudoコマンドを先頭につけます。
※ 途中でIs this ok [y/d/N]:と対話する箇所があるのでyを入力

$ sudo yum install java-1.8.0-openjdk-devel                                                           
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                                                                 | 2.1 kB  00:00:00     
amzn-updates                                                                                              | 2.5 kB  00:00:00     
1045 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.171-7.b10.37.amzn1 will be installed
--> Processing Dependency: java-1.8.0-openjdk(x86-64) = 1:1.8.0.171-7.b10.37.amzn1 for package: 1:java-1.8.0-openjdk-devel-1.8.0.171-7.b10.37.amzn1.x86_64
--> Processing Dependency: libawt_xawt.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-devel-1.8.0.171-7.b10.37.amzn1.x86_64
--> Processing Dependency: libawt_xawt.so()(64bit) for package: 1:java-1.8.0-openjdk-devel-1.8.0.171-7.b10.37.amzn1.x86_64
--> Running transaction check
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.171-7.b10.37.amzn1 will be installed
--> Processing Dependency: java-1.8.0-openjdk-headless(x86-64) = 1:1.8.0.171-7.b10.37.amzn1 for package: 1:java-1.8.0-openjdk-1.8.0.171-7.b10.37.amzn1.x86_64
--> Running transaction check
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.171-7.b10.37.amzn1 will be installed
amzn-main/latest/filelists_db                                                                             | 5.7 MB  00:00:13     
amzn-updates/latest/filelists_db                                                                          | 1.2 MB  00:00:00     
epel/x86_64/filelists                                                                                     | 7.3 MB  00:00:01     
--> Processing Dependency: copy-jdk-configs >= 1.1-3 for package: 1:java-1.8.0-openjdk-headless-1.8.0.171-7.b10.37.amzn1.x86_64
--> Processing Dependency: lksctp-tools(x86-64) for package: 1:java-1.8.0-openjdk-headless-1.8.0.171-7.b10.37.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.171-7.b10.37.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.171-7.b10.37.amzn1               amzn-updates            249 k
 java-1.8.0-openjdk-headless            x86_64            1:1.8.0.171-7.b10.37.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: 144 M
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:00     
(2/5): java-1.8.0-openjdk-1.8.0.171-7.b10.37.amzn1.x86_64.rpm                                             | 249 kB  00:00:05     
(3/5): lksctp-tools-1.0.10-7.7.amzn1.x86_64.rpm                                                           |  89 kB  00:00:02     
(4/5): java-1.8.0-openjdk-devel-1.8.0.171-7.b10.37.amzn1.x86_64.rpm                                       |  12 MB  00:00:15     
(5/5): java-1.8.0-openjdk-headless-1.8.0.171-7.b10.37.amzn1.x86_64.rpm                                    |  39 MB  00:00:16     
---------------------------------------------------------------------------------------------------------------------------------
Total                                                                                            2.3 MB/s |  51 MB  00:00:21     
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-1.8.0.171-7.b10.37.amzn1.x86_64                                                          3/5 
  Installing : 1:java-1.8.0-openjdk-headless-1.8.0.171-7.b10.37.amzn1.x86_64                                                 4/5 
  Installing : 1:java-1.8.0-openjdk-devel-1.8.0.171-7.b10.37.amzn1.x86_64                                                    5/5 
  Verifying  : 1:java-1.8.0-openjdk-devel-1.8.0.171-7.b10.37.amzn1.x86_64                                                    1/5 
  Verifying  : 1:java-1.8.0-openjdk-1.8.0.171-7.b10.37.amzn1.x86_64                                                          2/5 
  Verifying  : 1:java-1.8.0-openjdk-headless-1.8.0.171-7.b10.37.amzn1.x86_64                                                 3/5 
  Verifying  : lksctp-tools-1.0.10-7.7.amzn1.x86_64                                                                          4/5 
  Verifying  : copy-jdk-configs-1.2-1.2.amzn1.noarch                                                                         5/5 

Installed:
  java-1.8.0-openjdk-devel.x86_64 1:1.8.0.171-7.b10.37.amzn1                                                                     

Dependency Installed:
  copy-jdk-configs.noarch 0:1.2-1.2.amzn1                             java-1.8.0-openjdk.x86_64 1:1.8.0.171-7.b10.37.amzn1      
  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.171-7.b10.37.amzn1       lksctp-tools.x86_64 0:1.0.10-7.7.amzn1                    

Complete!

Java8に切り替え

AWSではjavaバージョン管理にalternativesが使用されているため、ただインストールするだけではなく切り替え作業が必要となってきます。

*+が先頭についているjavaのバージョンが現在適用されているバージョンです。
Enter to keep the current selection[+], or type selection number:と対話する箇所があるので、jre-1.8.0である2を入力します。

Java

$ sudo alternatives --config java
There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number: 2

Javac

$ sudo alternatives --config javac

There are 2 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/javac
   2           /usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/javac

Enter to keep the current selection[+], or type selection number: 2

最後にバージョンの確認を行い、1.8.0に変わっていたら完了です。

$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-b10)
OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)
$ javac -version
javac 1.8.0_171

まとめ

インストールして満足するだけでなく、切り替え作業を忘れずにやりましょう!

tu-kun
「仲間をサポートして次のステップへのキッカケを与える」を自身のミッションとしてスタートアップCTOで活動中。 技術ではAWS設計/構築、Vue.js, Nuxt.js, Python, Ruby, Javaなど幅広く携わる。 他、ペルソナ構想〜MVP検証、顧客インタビュー、そして論理的に考え現実主義のため、チーム内の意見を現実可能なラインまで落とし込むのが得意。今はXRに興味あり
from-to
ふるさと開拓サービス「flato」の開発・運用をしています。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした