On April 16, 2019, Oracle changed its license to distribute Java SE. Now Oracle’s JRE can be used free of charge only for the home, or when developing software. This entailed various changes, such as the inability to download jvm without registering on the oracle website and closing the main repositories for installing java from packages.
The other day I needed to install Oracle Java JRE 8 on Ubuntu 18 and I just could not do it. The internet is full of instructions how to install Java on Ubuntu 18, but all of them became irrelevant at once. The popular webupd8team/java repository has moved to DISCONTINUED status. Installing from it will no longer work. There will be such a mistake:
Package oracle-java8-installer is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source https://xn--trdlsa-hrlurar-mib8ye.se/ bluetooth headset test E: Package 'oracle-java8-installer' has no installation candidate
Now you can install the Oracle JRE or SDK manually. For this you need:
- Register and log in to oracle.com.
- Download binaries or rpm package from the site.
- Copy files to target server.
- Manually install the Oracle JRE, set the path and environment.
I will describe in detail how to do this for two popular systems – Ubuntu and Centos. Let’s start with the more difficult, with Ubuntu 18.
Installing Oracle Java on Ubuntu
As I said above, to install oracle java, you need to download the binaries. To do this as I recently described in the article about setting up the ELK Stack does not work. Links are not available without authorization. So you need to register on the site and download the binaries to your computer. I will show how to do this using the example of Oracle Java 8. Go to the download page, log in and download jre-8u211-linux-x64.tar.gz.
Be sure to check the box next to Accept License Agreement. After downloading, copy the file to the target server where we will install Java 8. I use scp for this. I copy the file to the home directory /root. Create a directory for java and unpack the binaries there.
# mkdir /usr/lib/jvm # tar -zxf /root/jre-8u211-linux-x64.tar.gz -C /usr/lib/jvm
The JRE should be located in the /usr/lib/jvm/jre1.8.0_211 directory. Now we need to create symbolic links to the installed java. We do this with update-alternatives.
# update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.8.0_211/bin/java" 1500 # update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jre1.8.0_211/bin/javaws" 1500
Let set the JAVA_HOME variable that some applications use. To do this, add the following line to the /etc/environment file.
Save it and apply the change.
# source /etc/environment
Now check out what we did.
# java -version # echo $JAVA_HOME
It’s okay In case it is necessary to update or install another version of Java, then everything is done in the same way, only at the end there are links to a new directory with Java.
If you need to install the Oracle SDK, then you do the same thing, only download the binaries from another link – Java SE Development Kit.
It is all about the installation of Oracle Java on Ubuntu. In the general case, everything necessary has been done. But I am in the process of compiling one application encountered one error. I’ll tell you how I solved it.
Could not find tools.jar
The application used the gradle automatic build system, which terminated the build with an error.
* What went wrong: Execution failed for task ':compileJava'. > Could not find tools.jar. Please check that /usr/lib/jvm/jre1.8.0_211 contains a valid JDK installation.
I google a long decision. It consists with to set up the path to tools.jar, but I did not have this file at all in the system and I did not know where to get it. I do not understand the topic with java at all, for the first time I compiled the application myself. Out of the situation in the end as follows. I installed openjdk-8-jdk with the following command.
# apt install openjdk-8-jdk
It is installed in the /usr/lib/jvm/java-8-openjdk-amd64 directory. There in the libs directory with the file tools.jar. I just copied it to /usr/lib/jvm/jre1.8.0_211/lib, where oracle java is installed. After that, the compiling passed without errors.
Already after writing this article, I realized that I did not need to install the Oracle JRE, but the JDK, then everything would be right away without any errors. I hope this information will be useful to those who will look for a solution to a similar problem. It was from a misunderstanding of the differences between the JRE and the JDK.
What is Oracle JRE and JDK and what is the difference?
My initial fuss about installing and compiling Java applications was due to the fact that I did not notice that there are 2 completely different packages for installing Java.
- JRE – Java Runtime Environment. This is a software, that includes everything you need to run compiled java applications. The package includes a Java virtual machine (JVM), libraries, and the rest of the java infrastructure. This software has been paid since April 16th.
- JDK – the Java Development Kit. This is a complete SDK for developing Java applications. It includes everything that is in the JRE, plus a compiler (javac) and various utilities. Including tools.jar, which I lacked for the compiling, described above. JDK has long been paid, I do not remember from what time.
You can read more about these products and the differences between the JRE and the SDK on the official website at faq. Thus, if you only need to run already compiled java applications, the JRE package is sufficient. If you need to build a java program from source, install the SDK. I figured it out only at the time of this writing, so the article is not very consistent.
Installing Oracle Java on Centos
Installing Java SE Runtime Environment on CentOS is still not difficult, as there is a rpm package. The only inconvenience is that you need to manually download it from the site and transfer it to the server. To download you need to register on the site oracle.com. After logging in, you need to go to the download section and download the rpm package.
After that, we transfer it to the target server and install Oracle Java on CentOS with the following command:
# yum localinstall jre-8u211-linux-x64.rpm
After that, you can check the Java version in the console.
# java -version java version "1.8.0_211" Java(TM) SE Runtime Environment (build 1.8.0_211-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
You can set the $JAVA_HOME variable by analogy with the previous section on ubuntu. If you need to install the Oracle SDK, then you do the same thing, only download the binaries from another link – Java SE Development Kit.
This completes the installation of Oracle Java on Centos.
Before installing Oracle Java, do not forget that now it cannot just be used in a commercial environment. You have to pay if you need license. I think that in the near future, all projects will try to optimize work with the free OpenJDK. The number of Oracle JRE clients is clearly decreasing at times.
For me, it remains not clear moment with the work of Java on Windows. It is required for a lot of various services and hardware. In theory, now you have to pay for its use. How to deal with old hardware, to which there will be no updates? What do you think about this?