11

I wanted to install Temurin JDK both 8 and 11, I installed them by these steps

wget https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u312-b07/OpenJDK8U-jdk_x64_linux_hotspot_8u312b07.tar.gz
tar xzf OpenJDK8U-jdk_x64_linux_hotspot_8u312b07.tar.gz

sudo mv jdk8u312-b07/ /usr/lib/jvm/temurinjdk-8-hotspot-amd64

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/temurinjdk-8-hotspot-amd64/bin/java" 1081 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/temurinjdk-8-hotspot-amd64/bin/javac" 1081

But I am not sure if this is 100% right and how do I generate .jinfo file is that even needed?

poqdavid
  • 257
  • 1
    I would recommend searching for documentation regarding the Temurin JDK or visit their forums/sites. Is there a read.me file or other installation instructions? –  Nov 14 '21 at 01:21
  • @TBr well there is and it just says do export PATH=$PWD/jdk8u312-b07/bin:$PATH and doesnt say anything about update-alternatives option which i like to use – poqdavid Nov 14 '21 at 09:52
  • The best answer I can give you is this then; unless there is another user who has also installed this software and has chosen to use it as you have, only they would be able to provide a satisfactory answer. –  Nov 14 '21 at 14:35

2 Answers2

28

You can use the Adoptium Debian / Ubuntu repository

  1. Add the Eclipse Adoptium GPG key

    wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo apt-key add -
    
  2. Add the Eclipse Adoptium apt repository

    echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
    
  3. Install the Temurin version you require

    sudo apt update # update if you haven't already
    sudo apt install temurin-8-jdk
    sudo apt install temurin-17-jdk
    
  4. Configure the default version

    sudo update-alternatives --config java
    
BuZZ-dEE
  • 14,223
  • 1
    E: The repository 'https://packages.adoptium.net/artifactory/deb una Release' does not have a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. – Aubergine Feb 15 '23 at 06:20
  • 1
    The Adoptium procedure fails at nearly every steup on Ubuntu Server 22.04.2 LTS (running in AWS). The error given in the comment above occurs, and also before that the warning 'Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). E: This command can only be used by root.' followed by 'W: GPG error: https://packages.adoptium.net/artifactory/deb jammy InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ...' – Corbell Apr 24 '23 at 14:24
  • This answer has minor flaws. The correct apt repository setup that worked in 03/2024 with Ubuntu 22.02 LTS is: https://askubuntu.com/a/1488200/18928 – user272735 Mar 07 '24 at 13:32
1

I extracted script from original AdoptOpenJDK deb package and modified version I use like:

wget https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.1%2B12/OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz

mkdir -p /usr/lib/jvm

sudo tar -xvvf OpenJDK17U-jdk_x64_linux_hotspot_17.0.1_12.tar.gz -C /usr/lib/jvm/

sudo ./java-alternative install /usr/lib/jvm/jdk-17.0.1+12 sudo ./java-alternative set /usr/lib/jvm/jdk-17.0.1+12 … sudo ./java-alternative remove /usr/lib/jvm/jdk-17.0.1+12

Source code of script:

#!/bin/sh

set -eu

priority=2222 #jdk_base_dir=/usr/lib/jvm/adoptopenjdk-11-hotspot-amd64 #jdk_base_dir=/usr/lib/jvm/jdk-17.0.1+12 jdk_base_dir="$2"

if [ ! -d "$jdk_base_dir" ] then echo "Invalid java directory. Choose one of: "; ls -1d /usr/lib/jvm/* exit fi

tools="jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jfr jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200 jexec jspawnhelper"

case "$1" in install) for tool in $tools ; do for tool_path in "$jdk_base_dir/bin/$tool" "$jdk_base_dir/lib/$tool" ; do if [ ! -e "$tool_path" ]; then continue fi

        slave=""
        tool_man_path="$jdk_base_dir/man/man1/$tool.1"
        if [ -e "$tool_man_path" ]; then
            slave="--slave /usr/share/man/man1/$tool.1 $tool.1 $tool_man_path"
        fi

        update-alternatives \
            --install \
            "/usr/bin/$tool" \
            "$tool" \
            "$tool_path" \
            "$priority" \
            $slave
    done
done

;; remove) for tool in $tools ; do for tool_path in "$jdk_base_dir/bin/$tool" "$jdk_base_dir/lib/$tool" ; do if [ ! -e "$tool_path" ]; then continue fi

        update-alternatives \
            --remove \
            "$tool" \
            "$tool_path"
    done
done

;; set) for tool in $tools ; do for tool_path in "$jdk_base_dir/bin/$tool" "$jdk_base_dir/lib/$tool" ; do if [ ! -e "$tool_path" ]; then continue fi

        update-alternatives \
            --set \
            "$tool" \
            "$tool_path"
    done
done

;; esac