AmazonLinuxにOpenJDK11と今更感が強いですが……
- Amazon Linux AMI release 2018.03
wgetで圧縮ファイルをダウンロード
$ wget https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
--2019-11-07 10:21:55-- https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
Resolving download.java.net (download.java.net)... 23.50.236.23
Connecting to download.java.net (download.java.net)|23.50.236.23|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 187513052 (179M) [application/x-gzip]
Saving to: ‘openjdk-11.0.2_linux-x64_bin.tar.gz’
openjdk-11.0.2_linu 100%[===================>] 178.83M 8.77MB/s in 21s
2019-11-07 10:22:15 (8.72 MB/s) - ‘openjdk-11.0.2_linux-x64_bin.tar.gz’ saved [187513052/187513052]
圧縮ファイルを展開
$ tar xzvf openjdk-11.0.2_linux-x64_bin.tar.gz
jdk-11.0.2/bin/jaotc
jdk-11.0.2/bin/jar
jdk-11.0.2/bin/jarsigner
jdk-11.0.2/bin/java
jdk-11.0.2/bin/javac
jdk-11.0.2/bin/javadoc
jdk-11.0.2/bin/javap
:
:
展開したディレクトリを/optへ移動
$ sudo mv jdk-11.0.2/ /opt/
デフォルトではOpenJDK7が入っていた為 java、jar、javacコマンドをalternativesで切り替え
$ sudo alternatives --install /usr/bin/java java /opt/jdk-11.0.2/bin/java 1
$ sudo alternatives --install /usr/bin/jar jar /opt/jdk-11.0.2/bin/jar 1
$ sudo alternatives --install /usr/bin/javac javac /opt/jdk-11.0.2/bin/javac 1
バージョン確認
$ java -version
java version "1.7.0_231"
OpenJDK Runtime Environment (amzn-2.6.19.1.80.amzn1-x86_64 u231-b01)
OpenJDK 64-Bit Server VM (build 24.231-b01, mixed mode)
……うまく切り替わっていなかった為再設定。
$ 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 /opt/jdk-11.0.2/bin/java
Enter to keep the current selection[+], or type selection number:
/opt/~に配置されている11.0.2を使用する為2を入力しEnter
その後再度コマンドで確認。
$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
$ jar --version
jar 11.0.2
$ javac -version
javac 11.0.2
最初に取得した11.0.2が設定されていることを確認。