In the tutorial, we show you how to install Java in Ubuntu Remote Server with Vutr Hosting VPS.
Technology
– Java
– Vutr VPS Hosting
Practice
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 https://download.oracle.com/otn-pub/java/jdk/11.0.1+13/90cf5d8f270a4347a95050320eef3fb7/jdk-11.0.1_linux-x64_bin.tar.gz
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 :
JAVA_HOME="/usr/local/oracle-java-8/jdk1.8.0_191"
Apply the changes to your current session by cmd: source /etc/environment
Verify the JAVA_HOME
environment variable by cmd: echo $JAVA_HOME