Select Page

You’re probably looking for information on how to install multiple versions of Java on Linux as part of a migration piece of work and/or a new deployment activity after spinning up a new Linux server which has a different version of Java running than what your Java web application was compiled in. Whatever Java version your application is compiled in needs to be the same Java version that is running on your web application server to ensure it works without issues (or even just works!).

So, let’s assume you’ve got the handy yum tool installed on your Linux box which allows you to easily run handy commands to install software. Within yum you can find lots of handy versions of java just sitting around waiting to install them. Take a look at all the Java packages within yum.

What you’ll notice is that the majority of them are utilising the OpenJDK setup. This is a handy open source version of the Java platform. So all you need to do is get it installed then get it configured. Simple.

 

Check Current Java Version Installed

Firstly you need to check the current version of Java that you have installed on your Linux box. To do this simply run the following command;

 

java -version

 

 

Install Java 1.8 Version on Linux Using Yum

Simply run the following command to install the latest version of Java (whatever the latest version is on your system);

 

sudo yum instal java-1.8.0-openjdk

 

Configure Linux to Use the New Version of Java via Alternatives

On Linux machines you can configure multiple versions of Java to run via the ‘alternatives’ feature. This essentially allows you to install multiple Java versions alongside each other without having to worry about the specifics. This allows you to have multiple versions of Java installed, and still configure a default.

Which basically means that when you run any default java command that it will run against whatever alternative has been configured to point at the different versions of Java installed on your Linux box.

To check this, simply run the command;

 

sudo alternatives --config java

 

Which will allow you to configure which is the default Java version.

And it’s as simple as that. Install as many versions of Java as you need, but you can only use one of them at once.

If you have multiple applications running which all require different versions of Java then you have a couple of options. Either upgrade everything so they are all running the latest version of Java so you can keep everything on a single server. Or move applications to their own servers to give yourself the maximum control.

The following two tabs change content below.

Michael Cropper

Founder & Managing Director at Contrado Digital Ltd
Michael has been running Contrado Digital for over 10 years and has over 15 years experience working across the full range of disciplines including IT, Tech, Software Development, Digital Marketing, Analytics, SaaS, Startups, Organisational and Systems Thinking, DevOps, Project Management, Multi-Cloud, Digital and Technology Innovation and always with a business and commercial focus. He has a wealth of experience working with national and multi-national brands in a wide range of industries, across a wide range of specialisms, helping them achieve awesome results. Digital transformation, performance and collaboration are at the heart of everything Michael does.