Installing Java 7 JDK

First, check whether Java 7 is already installed:

java -version

You should expect output similar to the following, which lists a Java version that starts with 1.7. (the "1.7" refers to Java 7):

java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

If instead, you see a message containing:

  • java version "1.6..." (or anything else earlier than 1.7)

or you encounter this message

  • java: command not found

then it is likely that you will need to install one of the latest Java 7 JDKs.

You will need need to download and install either the Java 7 OpenJDK or Oracle's Java Development Kit (JDK) manually. Make sure you get JDK 7 and not 6; and the JDK (a Java package that includes a development kit as well as a runtime environment), not the JRE (runtime environment alone).

Note: Depending on your system's access permissions, you may need root (e.g. sudo) privileges to perform most or all of following actions.

To install the Java 7 OpenJDK, execute the following command:

  • sudo apt-get install openjdk-7-jdk

Check that it is properly installed with:

java -version

You should now expect output similar to the following:

java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

To install Oracle's Java Development Kit (JDK), follow these instructions:

Open a browser and go to http://www.oracle.com/technetwork/java/javase/downloads/index.html.

  1. Find JDK7 (not JDK 6)
  2. Click the "Download JDK" button" in the "Java Platform, Standard Edition" box.
  3. Click the "Accept License Agreement" radio button.
  4. Find the appropriate download link for your system. This link's text will:
    • Contain linux
    • End in .rpm (not .tar.gz)
    • Contain either x64 or i586 depending on whether your Linux distribution is 64-bit or 32-bit, respectively.


      To find out which distribution you have, 64-bit or 32-bit, at a Terminal (shell) command line, enter:

      uname -p

      A 64-bit system will report x86_64, while a 32-bit system will report something like i386, i486, i586, or i686.

  5. Click the appropriate download link.

This should let you download the JDK.

Run that file. (In the command below, the filename jdk-7u13-linux-x64.rpm is used as an example, representing the installer for Java 7 update 13, for 64-bit Linux systems. Please substitute the actual filename of the .rpm file you downloaded.)

rpm -Uvh jdk-7u13-linux-x64.rpm


You can safely ignore any Error: Could not open input file: {file_pathname}.pack messages.

Under Ubuntu or other Debian Linux-based systems, if you encounter this error (or a similar error):

The program 'rpm' is currently not installed.

See this comment for alternative download and installation instructions.

Check that it is properly installed with:

java -version

You should now expect output similar to the following:

java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

If after following the steps above, the reported version of Java is for some reason incorrect, you can manually correct this via your Linux 'alternatives' mechanism. This allows you to specify that several key Java commands, including the all-important java and javac commands, should always be run from your newly-installed copy of Java 7, instead of being run from some older version of Oracle's Java or from a version of OpenJDK, if either/both might also be installed on your system:

update-alternatives --install /usr/bin/java java /usr/java/latest/bin/java 20000
update-alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 20000

(By convention, if you've installed Java by running the rpm command, the path /usr/java/latest should always point to the latest installation of Java on your system, according to one of Oracle's JDK RPM Installation for Linux installation guides. If that directory does not exist on your system, you should substitute the actual filesystem paths to your java and javac commands; for example, /usr/lib/jvm/jdk1.7.0_25/java and /usr/lib/jvm/jdk1.7.0_25/javac for an installation of Java 7, Update 25 in one recent installation on an Ubuntu system, wherever you see /usr/java/latest/bin/java or /usr/java/latest/bin/javac in the relevant commands, both above and below.)

You can then choose to make the key java and javac commands point to your newly-installed copy of Java 7, by:

  • Entering each of the following commands in succession.
  • When prompted, typing the number (0, 1, 2 ...) next to the options that mention /usr/java/latest/bin/java and /usr/java/latest/bin/javac, respectively (or the actual filesystem paths to your java and javac commands):


update-alternatives --config java

and

update-alternatives --config javac

Check the Java version again by executing:

java -version


You should now see output similar to the following:

java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

You can find more detailed instructions on installing Java under Linux at: http://www.oracle.com/technetwork/java/javase/index-137561.html#linux