How to install Java on Ubuntu Remote Server – Vutr Hosting VPS Example


In the tutorial, we show you how to install Java in Ubuntu Remote Server with Vutr Hosting VPS.


– Java
– Vutr VPS Hosting


Create Vultr Vps

Follow the link to create a Linux Vultr VPS.


Use Putty to login Vultr VPS:


Install Default OpenJDK

– Update apt package index:

sudo apt update

– Install the default Java OpenJDK package:

sudo apt install default-jdk

– Verify the installation:

java -version

-> Output:

root@gkz-vps:~# java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment (build 11.0.1+13-Ubuntu-2ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.1+13-Ubuntu-2ubuntu1, mixed mode, sharing)
Install Oracle Java

Visit the Oracle’s downloads page, download the Java archive file:


curl -L -b "oraclelicense=a" -O

Create a directory for the Java installation:

sudo mkdir /usr/local/oracle-java-11

Extract the Java .tar.gz file:

sudo tar -zxf jdk-11.0.1_linux-x64_bin.tar.gz -C /usr/local/oracle-java-11

– Create new Java alternatives:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/oracle-java-11/jdk-11.0.1/bin/java" 1500
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/oracle-java-11/jdk-11.0.1/bin/javac" 1500
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/oracle-java-11/jdk-11.0.1/bin/javaws" 1500

– Check Java Version:

root@gkz-vps:~# java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

How to install others Java version (6, 7, 8)? -> Just follow the above steps.

Set the Default Java Version

When having multiple Java versions installed on the server, you can use update-alternatives tool to change the default version:

sudo update-alternatives --config java ->


Set the JAVA_HOME Environment

Use sudo update-alternatives --config java to find where Java is installed:


Open file /etc/environment by command: sudo nano /etc/environment
Then add JAVA_HOME at the end of the file :


Apply the changes to your current session by cmd: source /etc/environment

Verify the JAVA_HOME environment variable by cmd: echo $JAVA_HOME

By grokonez | November 23, 2018.

Related Posts

Got Something To Say:

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