How To Install Java on Linux Virtual private

In this article we will explain how to install Java on a Linux VPS server running Ubuntu. Here we are also going to learn how to setup  Java home variable as well as overview few management steps to get you begun

 

  • Install Java on Ubuntu VPS Server via default packages

 

The 1st method to install Java on Ubuntu based Linux VPS server is via default packages. Start the process by updating the present available packages to the most recent version:

 

apt-get update && apt-get upgrade

 

When it completes, install the most recent form of Java Runtime Environment (JRE) by running this following command:

apt-get install default-jre

 

It is likewise possible to install Java Development Kit (JDK). It is needed by particular programming or used to compile Java programs. JDK incorporates JRE, subsequently there's no disservice in the event that you pick this method.

apt-get install default-jdk

 

All set!! Java is prepared for use on your Ubuntu based Linux VPS server. You can double check on the off chance that it was appropriately set up with these commands:

java -version

javac -version

 

The result will look similar to:



  • Install Java on Linux VPS server via Oracle JDK

On the other hand, it is conceivable to install Java on Ubuntu utilizing the official Oracle JDK. Start by updating your present packages to the most recent version:

 

apt-get update && apt-get upgrade

 

For this case, we are going to utilize third party library oversaw by WebUpd8. To actualize it less easier, install the accompanying package first:

 

apt-get install software-properties-common

 

Now, get the Java PPA using given command:

add-apt-repository ppa:webupd8team/java

 

At last, you may install Java on your Linux VPS server machine by running the following command:

apt update; apt-get install oracle-java9-installer

 

All done, Java is successfully installed on your Linux VPS server. You can verify it by checking the version by running these two commands:

java -version

javac -version

 

The result will look similar to:

 

  • Managing Java on Your Linux VPS server

One single web server can have different Java installations. You can set the default version utilizing the following command:

update-alternatives --config java

 

There are three different options for the alternative java (providing /usr/bin/java).

Selection     Path                                     Priority Status
------------------------------------------------------------
 0      /usr/lib/jvm/java-7-oracle/bin/java                      1071 auto mode
 1      /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java           1081 manual mode
 2      /usr/lib/jvm/java-8-oracle/jre/bin/java                  1081 manual mode
* 3       /usr/lib/jvm/java-9-oracle/bin/java                      1091 manual mode


Press <enter> to keep the current choice[*], or enter selection number:

 

Put the number from the choice menu which you want to utilize as the default one. You can likewise perform this with other Java commands, for example,

 

  • The compiler – javac

  • The documentation generator – javadoc

  • The JAR signing tool – jarsigner

 

Given below is the syntax that will perform the job:

update-alternatives --config javac
update-alternatives --config javadoc
update-alternatives --config jarsigner

  • Setting Java Home Environment

Another helpful thing to know is the means by which to set the JAVA_HOME variable. Most applications expect it to discover the area of your Java installation. The beforehand utilized command can enable you to find the Java installation location:

 

update-alternatives --config java

 

 

Once you have copied the Installation location, you should alter environment document situated in the and etc directory:

nano /etc/environment

nano /etc/environment

 

Put the line given below at the end to set the JAVA_HOME value:

JAVA_HOME="/usr/lib/jvm/java-9-oracle/bin/java"

 

Use CTRL+X to end editing process and save the modifications. Now ensure the modifications are applied properly using below command:

source /etc/environment

 

You can recheck, whether it is active using:

echo $JAVA_HOME

 

On the off chance that you took after the directions effectively the screen will prompt the JAVA_HOME variable that you entered:

 

 

All done, now you are ready with Java on your Linux VPS server.