Site Overlay

Installing Oracle Java on Manjaro / Arch

Linux distributions normally ship with the OpenJDK Java. Anyone who has ever tried to develop in Java will come to a point, where it is difficult to get around Oracle’s official Java installation. So there are several questions connected to Java: (1) Do I need the JRE, the JDK or both? (2) How can I install Oracle Java on my Arch / Manjaro machine? (3) Do I have to remove the OpenJDK java?

JRE or JDK or both?

If you are not going to develop in Java, the JRE is enough. JRE is the the “Java Virtual Machine” which translates the precompiled Java byte code into instructions which your particular OS environment will understand. Running online applets which have been embedded into HTML code requires such a JRE. In the past, I often had problems with banking applications run under OpenJDK so that there was virtually no way around Oracle’s jre. Today, though, OpenJDK seems to have come a long way and even applications as exposed as Eurex Trader are running without problems under OpenJDK’s IcedTea JRE.

Only if you are going to develop your own Java applications, you will need the JDK – and my experience from the past is that it is preferable to use Oracle’s Java by default.

In case you go for the JDK, the question is: Do I still need the JRE on top?

According to this post, the answer is clearly “No, you don’t.”. This is because the JDK already includes the corresponding Java Runtime Environment:

jdk contains jre. but you can consider install jdk-docs as well

 

Installing the Java SDK on your Manjaro / Arch machine

You can either use the pacman gui or go for the console based yaourt installation. I am going to show how to install with yaourt. At your command prompt, issue

yaourt will respondd with a flurry of output that looks like this:

Installation candidates suggested by yaourt
Installation candidates suggested by yaourt

Here is how to read that output:

  • things marked in red are deprecated versions, which you should not install unless there is a compelling reason;
  • the fields in blue are the “votes” which were given for the package – you can use them as a proxy for what should be installed if you are unsure what to pick;
  • the fields in yellow are a popularity index – no idea how this is computed but it should have roughly the same meaning as the votes

Based on these number of votes, it is easy to asses which installation to pick: number 21 with more than 700 votes is the current Oracle Java SDK this is version jdk 8u102-1. There is a more recent version of Oracle Java 9, though – but this has not been officially released by Oracle and still is in the state of a development snapshot. So

OpenJDK and Oracle Java on the same machine?

I had some trouble when I tried to install Oracle Java alongside Ubuntu’s default OpenJDK in the past. According the discussion linked above, however, having both JDKs on the same machine works without problems:

In fact you don’t need to remove open jdk, in your system, the oracle jdk and open jdk can […] exist at the same time.

The tricky question then is: How can I “switch” between the jdks? On Arch Linux this is really easy thanks to the archlinux-java command. You can enquire, which Java version is currently activated by default and (given root privileges) change the default setting: