OpenJDK 8 : インストール2022/08/29 |
OpenJDK 8 をインストールします。
|
|
[1] | OpenJDK 8 のインストールと動作確認です。 |
root@dlp:~#
apt -y install openjdk-8-jdk
root@dlp:~#
cat > /etc/profile.d/java.sh <<'EOF'
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java))))) export PATH=$PATH:$JAVA_HOME/bin EOF
root@dlp:~#
root@dlp:~# source /etc/profile.d/java.sh
java -version openjdk version "1.8.0_342" OpenJDK Runtime Environment (build 1.8.0_342-8u342-b07-0ubuntu1~22.04-b07) OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode) # テストプログラムを作成して動作確認
root@dlp:~# cat > java_test.java <<'EOF'
class java_test {
public static void main(String[] args) {
System.out.println("Hello Java World !");
}
}
EOF
root@dlp:~# javac java_test.java root@dlp:~# java java_test Hello Java World ! |
[2] | 公式リポジトリから複数バージョンをインストールしている場合は [update-alternatives] で切り替え可能です。 |
root@dlp:~# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
root@dlp:~# update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
root@dlp:~# java -version openjdk version "1.8.0_342" OpenJDK Runtime Environment (build 1.8.0_342-8u342-b07-0ubuntu1~22.04-b07) OpenJDK 64-Bit Server VM (build 25.342-b07, mixed mode)root@dlp:~# javac -version javac 1.8.0_342 |
Sponsored Link |
|