How to change openJDK version to 8 from 17 at Ubuntu18.04

How to change openJDK version to 8 from 17 at Ubuntu18.04

  • 目次

    I share how to change openJDK version to 8 from 17.

    Environment

    • Ubuntu 18.04 LTS that is already installed openJDK 17.

    Methods

    # Install openjdk 8
    $ sudo apt -y update
    $ sudo apt -y install openjdk-8-jdk
    $ java --version
    openjdk 17.0.3 2022-04-19
    OpenJDK Runtime Environment (build 17.0.3+7-Ubuntu-0ubuntu0.18.04.1)
    OpenJDK 64-Bit Server VM (build 17.0.3+7-Ubuntu-0ubuntu0.18.04.1, mixed mode, sharing)
    
    # Change java version
    $ sudo update-java-alternatives  --jre -s java-1.8.0-openjdk-amd64
    $ sudo update-java-alternatives  --jre-headless -s java-1.8.0-openjdk-amd64
    $ sudo update-java-alternatives  -s java-1.8.0-openjdk-amd64
    update-alternatives: エラー: mozilla-javaplugin.so の alternatives がありません
    update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/IcedTeaPlugin.so
    ### Occured error. But no problem since it work well. 
    
    # Check java version
    $ sudo update-alternatives --config java
    alternative java (/usr/bin/java を提供) には 2 個の選択肢があります。
    
      選択肢    パス                                          優先度  状態
    ------------------------------------------------------------
      0            /usr/lib/jvm/java-17-openjdk-amd64/bin/java      1711      自動モード
      1            /usr/lib/jvm/java-17-openjdk-amd64/bin/java      1711      手動モード
    * 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      手動モード
    
    現在の選択 [*] を保持するには <Enter>、さもなければ選択肢の番号のキーを押してください:
    # Check java command to 8
    $ ls -ltr /etc/alternatives/java*
    lrwxrwxrwx 1 root root 53  6月 11 22:39 /etc/alternatives/javah.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javah.1.gz
    lrwxrwxrwx 1 root root 43  6月 11 22:39 /etc/alternatives/javah -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javah
    lrwxrwxrwx 1 root root 56  6月 11 22:53 /etc/alternatives/java.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
    lrwxrwxrwx 1 root root 46  6月 11 22:53 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
    lrwxrwxrwx 1 root root 53  6月 11 22:53 /etc/alternatives/javac.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javac.1.gz
    lrwxrwxrwx 1 root root 43  6月 11 22:53 /etc/alternatives/javac -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javac
    lrwxrwxrwx 1 root root 55  6月 11 22:53 /etc/alternatives/javadoc.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javadoc.1.gz
    lrwxrwxrwx 1 root root 45  6月 11 22:53 /etc/alternatives/javadoc -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javadoc
    lrwxrwxrwx 1 root root 53  6月 11 22:53 /etc/alternatives/javap.1.gz -> /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javap.1.gz
    lrwxrwxrwx 1 root root 43  6月 11 22:53 /etc/alternatives/javap -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javap
    
    # Close terminal and set JAVA_HOME variable
    $ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
    $ export PATH=/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin:$PATH
    $ export CLASSPATH=.:/usr/lib/jvm/java-1.8.0-openjdk-amd64/lib
    
    # Check java version
    $ java -version
    openjdk version "1.8.0_312"
    OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~18.04-b07)
    OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
    

    Reference

    comments powered by Disqus