26

I downloaded Java 11 in the form of OpenJDK from AdoptOpenJDK. From the tar.gz file I can extract a folder named jdk-11.0.3+7 with nested folders for bin, conf, lib, and so on. But no installer app found there.

➥ How should I install this downloaded Java release onto Ubuntu?

I can cd into the bin folder and execute commands like ./java --version. But I wonder if there is a usual routine for placing the Java implementation somewhere specific, and arranging environment variables, setting default path, etc. On macOS, an installer does all that for me automatically. As I newbie on Ubuntu, I'm uneducated.

Older Questions such as this one ask about using apt-get. My Question is not a duplicate, as here I am asking about downloads from AdoptOpenJDK rather than via package-installer such as apt-get.

enter image description here

2 Answers 2

53

AdoptOpenJDK is now superseeded by Adoptium

How to properly install Temurin JDK with update-alternatives

Adoptium provides a Debian / Ubuntu repository

wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo apt-key add -
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
sudo apt update
sudo apt install temurin-8-jdk
sudo apt install temurin-17-jdk

AdoptOpenJDK provides a Debian / Ubuntu repository.

You can install using the package management system, which is much simpler than installing it manually.:

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
sudo apt update
sudo apt install adoptopenjdk-8-hotspot  # Java 8 / HotSpot VM
sudo apt install adoptopenjdk-8-openj9   # Java 8 / OpenJ9 VM
sudo apt install adoptopenjdk-11-hotspot # Java 11 / HotSpot VM
sudo apt install adoptopenjdk-11-openj9  # Java 11 / OpenJ9 VM
sudo apt install adoptopenjdk-12-hotspot # Java 12 / HotSpot VM
sudo apt install adoptopenjdk-12-openj9  # Java 12 / OpenJ9 VM
sudo apt install adoptopenjdk-13-hotspot # Java 13 / HotSpot VM
sudo apt install adoptopenjdk-13-openj9  # Java 13 / OpenJ9 VM

You can switch between e.g. OpenJDK, AdoptOpenJDK and Adoptium by using the following command.:

sudo update-alternatives --config java
1
  • note that (as of today) the repo has no entry for ubuntu impish & jammy. just use hirsute instead of your distro
    – bernstein
    Mar 1, 2022 at 13:53
2

Since the use of apt-key was deprecated, you might see warnings like:

Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8))

Hence, I'd recommend to use the following way:

Option 1, use sdkman

$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
$ sdk install java 17.0.8-tem

Option 2, install by apt

$ apt install ca-certificates curl gnupg
$ install -m 0755 -d /etc/apt/keyrings

$ curl -fsSL https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /etc/apt/keyrings/adoptium.gpg
$ chmod a+r /etc/apt/keyrings/adoptium.gpg

$ echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list

$ apt update -y
$ apt install temurin-17-jdk

Verify the installation

Then verify your installed java by

$ java --version

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .