Ubuntu 24.04 OpenJDK 21 をインストールする方法
環境
Ubuntu 24.04
1.OpenJDK 21 のインストールを行います
# apt -y install openjdk-21-jdk
# cat > /etc/profile.d/java.sh <<'EOF'
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java)))))
export PATH=$PATH:$JAVA_HOME/bin
EOF
# cat > /etc/profile.d/java.sh <<'EOF'
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java)))))
export PATH=$PATH:$JAVA_HOME/bin
EOF
# cat > /etc/profile.d/java.sh <<'EOF' export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java))))) export PATH=$PATH:$JAVA_HOME/bin EOF
2.shファイルを起動します
# source /etc/profile.d/java.sh
# java --version
openjdk version "21.0.3" 2024-04-16
OpenJDK Runtime Environment (build 21.0.3+9-Ubuntu-1ubuntu1)
OpenJDK 64-Bit Server VM (build 21.0.3+9-Ubuntu-1ubuntu1, mixed mode, sharing)
# source /etc/profile.d/java.sh
# java --version
openjdk version "21.0.3" 2024-04-16
OpenJDK Runtime Environment (build 21.0.3+9-Ubuntu-1ubuntu1)
OpenJDK 64-Bit Server VM (build 21.0.3+9-Ubuntu-1ubuntu1, mixed mode, sharing)
# source /etc/profile.d/java.sh # java --version openjdk version "21.0.3" 2024-04-16 OpenJDK Runtime Environment (build 21.0.3+9-Ubuntu-1ubuntu1) OpenJDK 64-Bit Server VM (build 21.0.3+9-Ubuntu-1ubuntu1, mixed mode, sharing)
3. テストプログラムを作成して動作確認する
# cat > java_test.java <<'EOF'
class java_test {
public static void main(String[] args) {
System.out.println("Hello Java World 222 !");
}
}
EOF
# cat > java_test.java <<'EOF'
class java_test {
public static void main(String[] args) {
System.out.println("Hello Java World 222 !");
}
}
EOF
# cat > java_test.java <<'EOF' class java_test { public static void main(String[] args) { System.out.println("Hello Java World 222 !"); } } EOF
プログラムを実行する
# javac java_test.java
# java java_test