Introduction
Ubuntu distros are a reliable line-up of Debian-based Linux distributions for desktop solutions. It provides long term support for home and organisational workflows, maintaining a great visual experience at the same time. The Ubuntu Long Term Support(LTS) version 16.04 is available to download for free with 5 years of guaranteed security updates and support. It makes Ubuntu 16.04 LTS a perfect platform for server-side workloads. It is available at E2E Cloud here.
If you pair Java with the Ubuntu Linux platform, you get reliable cloud servers. Since Java is platform dependent, it runs perfectly in the Ubuntu environment. The stable architecture of Ubuntu 16.04 LTS provides a smooth experience while setting up the same.
This article will give detailed instructions to set up JVM (Java Virtual Machine) and Java Development Kit(JDK) on your Ubuntu distribution. It will enable you to get started with Java Applications development and deployment.
Prerequisites
- An Ubuntu 16.04 server configured with a static IP address. You can get your Linux-based server here at affordable hourly prices. Creating a new account is easy, and you can get started within a few minutes. It is that simple!
- Creating a sudo (Super User Do) non-root user. You will get help articles about the process once you create a valid account on our website.
Steps for Installing the Default JDK/JRE
One good thing about Ubuntu 16.04 LTS is that it comes with an integrated Java package. It will most likely install the OpenJDK11 version. Though, OpenJDK8 is the most used and stable industry version in use.
$ sudo apt-get update
Next, to explicitly install Java Runtime Environment (JRE), run the following code:
$ sudo apt-get install default-jre
You can also install the Java Development Kit(JDK) by the same process. It will take a little bit more disk space because JDK itself contains JRE. But it can be helpful if you plan to work with developmental Java features. It is usually not required for simple Java programs.
$ sudo apt-get install default-jdk
Steps for Installing the Oracle JDK
There is also the option for installing the official JDK provided by Oracle. The steps are given below. You need to integrate Oracle’s PPA repository with your current session and then update your own package repository.
$ sudo apt install python-software-properties
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
This process used to work before 2019. It now produces a disclaimer as the output on the screen as follows:
The best workaround for this issue is to download the Java 11 installer from Oracle. Or, you can switch to OpenJDK or some other JDK distribution. The exact reason being, Oracle now uses a commercial license. It means you can use Java free of cost for development and testing. But it requires a fee for commercial production workflows.
Steps to Manage Java
The versatility of Ubuntu 16.04 lies in its property that enables a user to install multiple versions of Java on one server. Also, each version is individually configurable. The update-alternative command helps assign a default terminal version for Java. There can be 3 or 5 versions of Java installed at one single instance. You can select any one of those to be set as the default one.
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status --------------------------------------------------------------------------------
*0 /usr/lib/jvm/java-14-openjdk-amd64/bin/java 1411 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-14-openjdk-amd64/bin/java 1411 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode
The above process is also applicable for Java Compiler (javac), the documentation generator (javadoc), the JAR signing tool (jarsigner), and more commands.
Steps to the JAVA_HOME Environment Variable
For this process, you need to find the installation location of Java. For that, run the following command:
Then you need to copy your preferred installation path and open /etc/environment file as shown:
Then you need to add the following t the end of the file:
For example, it should look like this:
Now you have to save and close the file and then reload it:
The final step is to check whether all the environment variables are set correctly. Run the following command to check that:
Conclusion
The steps mentioned above empower you to install Java on your Linux-based Ubuntu server distribution. Now you can run Java-based applications directly on the cloud without thinking about security and performance. E2E Cloud provides affordable Linux-based cloud solutions. These are perfect for object-oriented development and workflows. The reliability of Ubuntu distros and the feature-rich approach of Java development together help establish and maintain a secure cloud-based infrastructure for various companies.