Install OpenJDK 11 LTS in the Ubuntu 20.04 LTS

André B. Silva
2 min readMay 26, 2020

--

DO NOT DO THIS:

Probably you would want to install OpenJDK 11 by using Ubuntu command line by the default Ubuntu packages repository:

sudo apt install open-11-jdk -y

Despite being the simplest and most practical way, it’s highly NOT recommended to do that way.

There’s a better way to install and set OpenJDK, not only Ubuntu but in all your Linux distributions. If it is necessary to disable, configure, update or remove OpenJDK, there is a way in which you have full control over this tool within your operating system.

DO THIS:

1. Create a Development Tools directory in your home directory, called DevTools (or use an appropriate name):

sudo mkdir ~/DevTools

TIP: Use that directory to install any others development tools, software development kits et all.

2. Create a sub-directory, in the DevTools, called JDK:

sudo mkdir ~/DevTools/JDK

3. Download the OpenJDK 11 LTS Version (“tar.gz”), here:

https://adoptopenjdk.net

3.1 Check for the correct OpenJDK file download:

ls -l ~/Downloads

4. Extracting OpenJDK file:

tar -zxvf ~/Downloads/OpenJDK11U-jdk***tar.gz -C ~/DevTools/JDK/

The -C option changes the destination directory for the file extraction. This avoids having to move the directory after extracting it.

4.1 Check for the correct OpenJDK file extracted:

ls -l ~/DevTools/JDK/

5. Set the path of OpenJDK directory in the Ubuntu environment variables. Edit the following file:

sudo nano ~/.bashrc

5.1 Add to the end of the .bashrc file:

DEV_TOOLS="/home/$USER/DevTools"
JAVA_HOME="$DEV_TOOLS/JDK/jdk-11.0.7+10"
export JAVA_HOME
PATH="$JAVA_HOME/bin:$PATH"

5.2 Reset PATH:

source ~/.bashrc

6. Testing java command (JRE):

java --version

7. Testing javac command (JDK):

javac --version

I hope that helped, answered any questions, clarified something in a simple way or at least established a new option for working with OpenJDK.

I would like to express my sincere apologies for English as my second language.

Any doubts, suggestions, information etc. Get in touch by email: barcelos.ds@gmail.com

Thank you!

--

--