How to Install Java on a Dedicated Server?
Installing Java on a dedicated server isn’t quite the same as a desktop machine where visiting a URL, clicking and confirming, then voila you’re done. Installing Java on a KnownHost dedicated server hosting account isn’t a huge undertaking, but there is a bit more to it.
Installing Java Prerequisites
Before running through the steps to install, first make sure that:
- you have a user account that can execute sudo (you must have sudo privileges)
- yum package manager is installed, configured and usable by your user account
- you’re able to connect, get to a terminal prompt and are ready to go
Deciding on a Java Version
Knowing how to install Java on a dedicated server is one thing. Knowing which flavor of Java to install on a dedicated server is another.
Java comes in 4 different platforms:
- Java Enterprise Edition [Java EE]
- Java Micro Edition [Java ME]
- Java Standard Edition [Java SE]
The most popular platform for this scenario is Java SE.
What’s Your Intent
If you’ve decided on Java SE, it’s now time to question whether you’ll be doing development and programming tasks or if you’ll just be wanting to execute Java apps.
For development and programming using Java, you’ll be wanting the Java Development Kit. It’s available free and open source as OpenJDK.
For cases where you just want to be able to run Java applications but don’t need a full-blown development environment, the choice is the Java Runtime Environment, available free and open source as OpenJRE.
Which Version Number to Install
You’ve decided on Java SE (OpenJDK), so now what? The next critical decision is in choosing what numerical version of Java (which version) you’d like to install.
If you’ve dealt with CMS systems, like WordPress, enough, you may be conditioned to installing the most recent version, so that you stay current and are protected against the latest exploits. Java is a bit different.
As of September, 2020, the most recent version is Java SE 15. OpenJDK based on Java SE 15 will continue to be updated until March 2021. Sounds good right?
Java, and other enterprise software, operates with a product lifecycle management policy known as long-term support (LTS). With LTS, a particular version of the software is singled out to be actively maintained and supported for a much longer period of time.
The whole idea behind LTS is that companies can spend their time and money in developing based on a stable, relatively unchanging platform, that they can depend on for years to come.
Java 11 came out in September, 2018 and will be supported for roughly a decade!
If you’re running a mission critical enterprise on Java applications, then the prudent course of action is to choose the current LTS version of Java, Java 11.
If you’re still considering Java 15 or some other recent release, have a look at the in your face discussion of why installing anything other than the LTS version of Java is risky, at best.
Let’s move ahead with the plan being to install Java 11 OpenJDK in a KnownHost dedicated server running CentOS.
How to Install Java 11 OpenJDK
Installing OpenJDK 11 will, by nature of the install packages, also install the Java Runtime Environment (OpenJRE 11).
Step 1 – Make sure the package repository is fully updated
sudo yum update
Step 2 – Install OpenJDK (look for Complete! message at the end)
sudo yum install java-11-openjdk-devel
Step 3 – Confirm install was a success
What About Multiple Java Versions
If you’ve just installed OpenJDK 11, you might now have two different versions of Java available on the server. This is actually a good thing, for developers, since some dev work may want to be targeting an older version, like Java 8 (the previous LTS version of Java).
There can only be one default version at any particular point in time and you need to know what versions are available.
Execute the following to see what Java version alternatives are available to choose from on the server at present:
sudo alternatives --config java
Updating the default version can be done with:
sudo update-alternatives --config java
If you see two, three, four or more in the list, you’ll be prompted to type the number representing which one in the list you’d like to set as the default version of Java on the machine. Pick the number and press [ENTER].