X

How to Run Java Files on CentOS with the JRE

Spread the love

There is a large amount of useful software for Linux packaged away in jar files, the main reason and benefit being that it allows for platform independence. For example, if you find a java utility that can minify, compress, and concatenate static files like JS and CSS for your website, you can download and use it on your own web server, regardless of the operating system.

But, you can’t run these jar files by default on any given Linux installation. A special interpreter needs to interpret the “bytecode” that they contain, and that is what the Java Runtime Environment (JRE) provides. Most Linux packages can be installed by using either the default repositories or by using the extended ones. (In the case of CentOS, these are the “EPEL” repositories.)

However, Java isn’t one of them. You need to download it from Oracle’s website and consent to a license agreement. In fact, this can be a bit of a problem as shown below.

In this tutorial, we will show you how to install the Java SE JRE on Linux so that we can run these files.

Getting the RPM Packages

If you open your server CLI and type “java”, nothing happens:

To get this command along with its features, navigate to the JRE download page and select the “JRE” download. This will bring you to a page with a list of packages. To find the one we want, we first need to get the architecture of your system – either 32-bit, or 64-bit. Type the following command:

arch

And you should get an output similar to this:

If like on the above system your output is “x86_64”, then you have a 64-bit system. If on the other hand your output is i386, then you have a 32-bit system. In today’s world, most systems are going to be 64-bit unless it’s an older machine.

Downloading the RPM Package

Unfortunately, you can’t just copy the link and download it to your system with wget. If you try, something similar to this will happen when you attempt to execute the rpm file with “yum localinstall”.

You’ll get an error saying “Cannot open” and “Skipping”.

This is because you’ll get a license agreement instead of an RPM file. Oracle really wants to make sure that whoever downloads these files has agreed to their terms and conditions. In fact, the Java cookbook README.md specifies this:

Luckily, there are a couple of methods to agree to this agreement and download the files you need.

Method 1: Download with Browser

The most direct way is to accept the graphical license agreement, and click the appropriate download as shown here:

This will initiate the download onto your desktop via your web browser. It’s a large(ish) file – around 155 MB as of this article. Once it’s done, you will need to transfer the file onto your server either via FTP, or by placing it in a download location that your server can access and obtain with wget.

Method 2: Fooling the JRE Server with the Use of a Cookie

This “hacky” solution will download the file directly onto your server. But the way it’s done means that it might stop working in the future. This method worked at the time of the article being written.

First, get the name of the URL containing the RPM download. Then enter the following command:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "[DownloadURL]"

Replace [DownloadURL] with the name of the URL on the page. This time, you should obtain the full download instead of only a few KB containing the license agreement.

Installing and Verifying the JRE Environment

Execute the rpm file using this command:

yum localinstall [DownloadedFile]

It should install normally like this:

Once the install is complete, check whether the “java” command is working as it should:

And that’s it! You’ve successfully installed the latest version of the Java JRE on Linux. You can now run all kinds of “jar” files without worrying about compatibility issues.


Of course, you don’t have to do any of this if you use one of our Outsourced server support services, in which case you can simply ask our expert Linux admins to install the JRE for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, please share it with your friends on the social networks using the buttons on the left, or simply leave a reply below. Thanks.

Categories: Tutorials
admin:
Related Post