FactorPad
Faster Learning Tutorials

How to Install Java on Debian for an Apache Solr Installation

Apache Solr 6 (and 7) requires Java Runtime Environment 1.8 or greater and here we cover considerations for Debian-based Linux distributions.
  1. Understand Java - Java provides two libraries, the full JDK or Java Development Kit and the JRE or Java Runtime Environment.
  2. Debian versions - Debian 8 and Debian 9 each have different versions of JRE in the stable repository.
  3. GUI or headless? - In a server environment, when not running in a GUI, the headless JRE offers a lighter weight installation.
  4. Install from jessie-backports - On Debian 8 we need to download JRE version 1.8 from jessie-backports.
  5. Download from Oracle Java website - Another alternative is to download and install straight from the Oracle site.
by Paul Alan Davis, CFA, September 27, 2017
Updated: July 13, 2018
Here we focus on the Java JRE for an Apache Solr installation on two versions of Debian-based Linux distributions which may be appropriate for Ubuntu as well.

Outline Back Next

~/ home  / tech  / solr  / tutorial  / install java


Installing Java for Two Versions of Debian - Jessie 8 and Stretch 9

Beginner

Apache Solr version 6, (we will install version 7 in the next tutorial) the latest version as of this writing, requires the Java Runtime Environment 1.8 (JRE) or greater.

Apache Solr in Video

How to Install Java JRE for an Apache Solr Installation (13:15)

Videos can also be accessed from our Apache Solr Search Playlist on YouTube (opens in a new browser window).

For Those Just Starting Out

Consideration 1 - Understand the Java Installation

The full blown Java Development Kit (JDK) at the time of this writing is Version 8. So you are aware and to avoid confusion, the official version number is 1.8, and people often refer to version 8 as the same thing.

The Java Development Kit (JDK)

The full Java Development Kit (JDK) includes the required Java Runtime Environment for Apache Solr. So if you install the JDK this satisfies the requirements. However, the JDK is more suited for those who want to compile their own Java programs. Also, some software requires the whole JDK, but Apache Solr does not. So you should decide whether it fits your needs to install the full JDK. Here we will focus on the JRE.

The Java Runtime Environment (JRE)

The Java Runtime Environment (JRE) on the other hand is the software required to run Java programs, in this case Apache Solr. If you would like a smaller footprint on the server then install only the JRE.

If you are unsure as to whether you have Java installed on your system you can run java -version.

$ java -version openjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-1~bpo8+1-b11) OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

As you can see, I have version 1.8, or 8, after completing the steps in this tutorial for my Debian 8 Jessie operating system.

Consideration 2 - How to install the JRE on Debian

Assuming you only want to install the JRE, the next consideration depends on which version of Debian you have. On Debian 8 Jessie the default JRE downloaded using the default package manager using apt-get install will download the JRE version 1.7 which is not suitable for Apache Solr 6 (and 7). On Debian 9 Stretch the default JRE is 1.8, so that is easy.

Debian 8 Jessie

To see this on Debian 8 Jessie, first off start with a sudo apt-get update to update the cache of all stable packages to your local system. As of the time of this writing there are about 54,000 packages.

Next, to see which JRE programs are available use apt-cache -n search jre. This will scan the 54,000 packages and where it finds jre in the name field only, specified using the -n option, it will print a match.

$ apt-cache -n search jre jvm-7-avian-jre - lightweight virtual machine using the OpenJDK class library gcj-4.8-jre - Java runtime environment using GIJ/Classpath gcj-4.8-jre-headless - Java runtime environment using GIJ/Classpath (headless version) gcj-4.8-jre-lib - Java runtime library for use with gcj (jar files) gcj-4.9-jre - Java runtime environment using GIJ/Classpath gcj-4.9-jre-headless - Java runtime environment using GIJ/Classpath (headless version) gcj-4.9-jre-lib - Java runtime library for use with gcj (jar files) gcj-jre - Java runtime environment using GIJ/Classpath gcj-jre-headless - Java runtime environment using GIJ/Classpath (headless version) default-jre - Standard Java or Java compatible Runtime default-jre-headless - Standard Java or Java compatible Runtime (headless) icedtea-7-jre-jamvm - Alternative JVM for OpenJDK, using JamVM openjdk-7-jre - OpenJDK Java runtime, using Hotspot JIT openjdk-7-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless) openjdk-7-jre-lib - OpenJDK Java runtime (architecture independent libraries) openjdk-7-jre-zero - Alternative JVM for OpenJDK, using Zero/Shark openjdk-7-jre-dcevm - Alternative VM for OpenJDK 7 with enhanced class redefinition

The packages we are interested in discussing are default-jre, default-jre-headless. Also, later we will cover the JRE version 8 which is similar to these two files openjdk-7-jre, and openjdk-7-jre-headless.

Now to learn more about any of these packages you can use the apt-cache showpkg command. So let's review the first few lines and last lines of the default-jre output using that command. The output is about 170 lines long.

$ apt-cache showpkg default-jre Package: default-jre Versions: 2:1.7-52 (/var/lib/apt/lists/ftp.us.debian.org_debian_dists_jessie_main_binary-amd64_Packages) (about 160 lines trimmed) Dependencies: 2:1.7-52 - default-jre-headless (5 2:1.7-52) openjdk-7-jre (2 7~u3-2.1.1) Provides: 2:1.7-52 - java7-runtime java6-runtime java5-runtime java2-runtime java-runtime Reverse Provides:

Reviewing the output, we can see that the version is 1.7-52, and as mentioned for Apache Solr 6 (and 7), we need the JRE version 1.8 or greater, so on Debian 8 Jessie we will need to install a different version, which I will explain shortly.

Debian 9 Stretch

On Debian 9 Stretch, if you do an apt-cache showpkg default-jre as of the date of this document, the version number is 1.8-58, so this package will be suitable for a Solr 6 (and 7) installation. It can be installed using sudo apt-get update followed by sudo apt-get install default-jre if you are using a GUI, or sudo apt-get install default-jre-headless if you are using a headless server (see Consideration 3).

Consideration 3 - Do you want the GUI or headless version?

The next thing to consider is your environment. Are you installing the Java JRE on a machine with a GUI (graphical user interface) or on a command line only server? On the latter, you will be able to save space by installing only the components you need.

GUI environment

For a GUI environment, you will need the full version of the default-jre. So again, as mentioned earlier, if you are on Debian 9, and you want the GUI version, then install with the command sudo apt-get install default-jre.

Non-GUI server (headless) environment

If you intend to run Apache Solr on a server using the command line, then the default-jre-headless is sufficient. This will allow you to save space by installing only the portion of the JRE needed to run on a headless server.

Using apt-cache showpkg from above, here is a subset of the output.

$ apt-cache showpkg default-jre-headless Package: default-jre-headless Versions: 2:1.7-52 (/var/lib/apt/lists/ftp.us.debian.org_debian_dists_jessie_main_binary-amd64_Packages) (about 160 lines trimmed) Dependencies: 2:1.7-52 - openjdk-7-jre-headless (2 7~u3-2.1.1) java-common (0 (null)) default-jre (0 (null)) Provides: 2:1.7-52 - java7-runtime-headless java6-runtime-headless java5-runtime-headless java2-runtime-headless java-runtime-headless Reverse Provides:

So again, on my Debian 8 Jessie server, the default using the headless package will be 1.7, so we will need another way to get 1.8 which is the next topic.

On Debian 9 Stretch, the default-jre-headless package will install version 1.8 by default, adequate for Solr 6 (and 7).

Consideration 4 - For Debian 8 Install from jessie-backports

Now since the default-jre and default-jre-headless for Debian 8 Jessie automatically download version 1.7, we need to get version 1.8 from Jessie backports.

Debian provides information about backports at https://backports.debian.org/Instructions/ including caveats and download instructions. In summary, backports are not as fully tested by Debian and may come with incompatibilities with the stable release, so Debian provides all of the appropriate warnings.

There are two steps to download from Jessie backports.

Add link to jessie-backports

We need to point the Debian Advanced Package Tool to this new jessie-backports repository, which is not standard in a default Debian installation.

There are two ways to do this. First, we can add a line to the file /etc/apt/sources.list. Second, we can add a new file to the directory /etc/apt/sources.list.d/. Both will point the Debian Advanced Package Tool to where to find packages, meaning the commands apt-get and apt-cache both look here for the URL of where to find packages.

Using the first method, with your preferred text editor, add the following line to /etc/apt/sources.list using superuser privileges. For example, sudo vim /etc/apt/sources.list.

deb http://ftp.debian.org/debian jessie-backports main

Save and close the file. Now when you perform an apt-get update it will access both the stable and backports repositories.

Install JRE 1.8 from jessie-backports

Next, we will install the JRE 1.8 from this newly connected jessie-backports repository. Recall that the default-jre would install version 1.7, so in order to install version 1.8, we need to instruct Debian to go to the backports and search for a different file name. The first file is openjdk-8-jre for the full GUI version and for the command line version use openjdk-8-jre-headless. As always start with an update.

$ sudo apt-get update

Since we added another repository with the backports, the update is required to pull the list of files in the backports for Jessie. Once that is complete, we will do a sudo apt-get install with the -t option to tell Debian to get the target release, or the one specified, instead of the default. Next, we point to the jessie-backports and install two files, openjdk-8-jre-headless and ca-certificates-java.

$ sudo apt-get install -t jessie-backports openjdk-8-jre-headless ca-certificates-java Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: java-common libnspr5 libnss3 libpcsclite1 libxtst6 x11-common Suggested packages: default-jre equivs pcscd libnss-mdns fonts-dejavu-extra fonts-ipafont-gothic fonts-ipafond-mincho ttf-wqy-microhei ttf-wqy-zenhei fonts-indic The following NEW packages will be installed: ca-certificates-java java-common libnspr4 libnss3 libpcsclite1 libxtst6 openjdk-8-jre-headless x11-common 0 upgraded, 8 newly installed, 0 to remove and 113 not upgraded. Need to get 28.8 MP of archives. After this operation, 105 MB of additional disk space will be used. Do you want to continue? [Y/n] $ _

The point of the last part ca-certificates-java has to do with verifying the download with a certificate authority. We are instructing Debian to also download the version of ca-certificates-java from the backports, which is recommended.

In my case, as I have not installed ca-certificates-java before there are two versions available. First, the older version 20140324 which would be downloaded from the Jessie stable repository and another version 20161107~bpo8+1 which is downloaded from the backports. Information on these packages can be found on the Debian Package Manager documentation located at https://packages.debian.org.

$ apt-cache search ca-certificates-java ca-certificates-java - Common CA certificates (JKS keystore)

To verify that everything worked as planned, check the version number of the JRE after the installation using backports for Debian 8 Jessie.

$ java -version openjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-1~bpo8+1-b11) OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

Again, this would be much easier using the latest version of Debian 9 Stretch, but using the backports gives you an alternative is you are using Debian 8 Jessie, like I am here.

Download and Install from the Oracle Website

The fifth consideration, and an alternative to using the Debian package manager, is to download files straight from Oracle at http://www.oracle.com/technetwork/java/javase/downloads/index.html.

Read appropriate documentation on the Oracle website for installation instructions, as it is beyond our scope here.

Now you should have version 1.8 of the JRE installed on your system, whether that be on Debian 8 Jessie or Debian 9 Stretch. You are ready for the installation of Apache Solr 6 (and 7).

Certain aspects of Apache Solr are tricky so if you need help with this please feel free to reach out on social media, including at our FactorPad YouTube Channel.


Related Solr Reference Material


Questions and Answers

Q:  Will this work with Ubuntu?
A:  You will have to check yourself, but because Ubuntu is an offshoot of Debian and uses the Advanced Packaging Tool much of the functions described here will likely work with Ubuntu as well.


What's Next?

Our YouTube Channel offers a lot of free learning resources. Subscribe straight from here and see what else is available.

  • To see the current list of Solr tutorials, click Outline.
  • To learn more about our Solr resources, click Back.
  • To dive right in and install Solr, click Next.

Outline Back Next

~/ home  / tech  / solr  / tutorial  / install java



 
 
Keywords:
install java
intall jre
jre 8
intall solr
jre headless
install jdk apache solr
solr installation
default-jre
default-jre-headless
openjdk-8-jre
jessie backports
ca-certificates-java