Ubuntu 24.04 update-alternatives複数バージョンを切り替える
環境
Ubuntu 24.04
1.公式リポジトリから複数バージョンをインストールしている場合は
[update-alternatives] で切り替えます
# update-alternatives --config java There are 4 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode * 2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode 3 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 manual mode 4 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode Press <enter> to keep the current choice[*], or type selection number: 3 update-alternatives: using /usr/lib/jvm/java-21-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode
javacを切り替えます
# update-alternatives --config javac There are 4 choices for the alternative javac (providing /usr/bin/javac). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-21-openjdk-amd64/bin/javac 2111 auto mode 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode * 2 /usr/lib/jvm/java-17-openjdk-amd64/bin/javac 1711 manual mode 3 /usr/lib/jvm/java-21-openjdk-amd64/bin/javac 2111 manual mode 4 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode Press <enter> to keep the current choice[*], or type selection number: 3 update-alternatives: using /usr/lib/jvm/java-21-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
javaバージョンを確認します
# 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)
javacバージョンを確認します
# javac -version javac 21.0.3