0

This is my first time of using Ubuntu. I am trying to install java jdk-15 in my lap.I applied following steps.

  1. sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-15/bin/java 1
  2. sudo update-alternatives --config java
  3. sudo gedit /etc/environment => I saved the path (JAVA_HOME = "/usr/lib/jvm/jdk-15" )
  4. source /etc/environment ==> this step outputs "JAVA_HOME: command not found"

Why do I get this? Pls help me.

1 Answers1

0

Check your JDK install

First, ensure your desired JDK version is indeed installed:
javac -version should output some information.
To get an overview of the different JDK versions installed on your computer, you can use sudo update-alternatives --config javac. This command should display at least the JDK version you target.

Install JDK if needed

If no Java is installed, or if you don't have the version you wish, you will have to install it.

From Ubuntu repositories (easiest, best secured and supported)

openjdk-15 is available in Ubuntu repository for Groovy. Here are the different openjdk versions available per Ubuntu version :
https://packages.ubuntu.com/search?suite=default&section=all&arch=any&keywords=openjdk-&searchon=names

Once you've made your version choice, install it with sudo apt install open-jdk-VERSION-jdk.

From third party providers (more options available but more steps required)

If you really want openjdk-15 but run in another version than Groovy, you'll have two options:

  • take JDK 15 from Openjdk website and install it manually : https://openjdk.java.net/install/. You will have to download a tar.gz file, decompress it, and then move it into a folder that is part of your PATH. I would not recommend this option as it will require you to perform future JDK update manually.
  • there is also a nice alternative that consists in using AdoptOpenJDK PPA: https://adoptopenjdk.net/installation.html?variant=openjdk15&jvmVariant=hotspot#linux-pkg. If you go for it, you'll install JDK 15 with sudo apt install adoptopenjdk-15-hotspot. I would definitely recommend this option as it is easier to setup and you'll get updates when running sudo apt upgrade.

Once Java is installed, run sudo update-alternatives --config java and sudo update-alternatives --config javac to use this version by default, and check that javac -version now gives you the right version.

Define JAVA_HOME

In the /etc/environment file, you can follow this syntax (adapting it to your effective path):
JAVA_HOME=/usr/lib/jvm/adoptopenjdk-15-hotspot-amd64/bin/java
Notice that there's no space around "=" sign and the path can be unquoted.

Once done, use source /etc/environment or reboot your computer to take the change into account.

Now, if you enter echo $JAVA_HOME, it should display the path to your Java executable.

FloT
  • 2,326