How to install Java (JRE) in EC2 Ubuntu Server 18.04 LTS in 2 simple commands

By | April 23, 2020

First you need to have your instance up and running and to have ssh’d in. The first command you want to run is:

> java -version
You should get this response:

> Command 'java' not found, but can be installed with:
> sudo apt install default-jre            
> sudo apt install openjdk-11-jre-headless
> sudo apt install openjdk-8-jre-headless 

If you try running these commands you’ll end up with errors. The trick is to first run:

> sudo apt-get update

Then install the openjdk version you want. eg

> sudo apt install openjdk-8-jre-headless

You should then get:

> ubuntu@ip-172-31-20-232:~$ java -version
> openjdk version "11.0.7" 2020-04-14
> OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
> OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)


Note, to uninstall openjdk use this:

> sudo apt-get autoremove openjdk-8-jre-headless


Leave a Reply

Your email address will not be published. Required fields are marked *