Through this series we see how to install Java. In this article, we will look specifically at installing on Linux distributions that use yum such as Fedora, Red Hat, CentOS, and Amazon Linux.

Note In Amazon Linux, Java 7 JRE is already installed.

Java 8 JRE

Console - [user@hostname ~]$

1
sudo yum install java-1.8.0-openjdk

Java 8 JDK

Console - [user@hostname ~]$

1
sudo yum install java-1.8.0-openjdk-devel

Java 7 JRE

Console - [user@hostname ~]$

1
sudo yum install java-1.7.0-openjdk

Java 7 JDK

Console - [user@hostname ~]$

1
sudo yum install java-1.7.0-openjdk-devel

Java 6 JRE

Console - [user@hostname ~]$

1
sudo yum install java-1.6.0-openjdk

Java 6 JDK

Console - [user@hostname ~]$

1
sudo yum install java-1.6.0-openjdk-devel

Choosing Java Version

JRE

Console - [user@hostname ~]$

1
sudo /usr/sbin/alternatives --config java

Output

1
2
3
4
5
6
7
8
9
There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   3           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number:

Currently java 7 is selected, but can switch to java 8 by typing 3 then hitting Enter

JDK

Console - [user@hostname ~]$

1
sudo /usr/sbin/alternatives --config javac

Output

1
2
3
4
5
6
7
8
9
There are 3 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/java-1.6.0-openjdk.x86_64/bin/javac
   2           /usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/javac
*+ 3           /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/javac

Enter to keep the current selection[+], or type selection number:

Currently java 7 is selected, but can switch to java 8 by typing 2 then hitting Enter

Setting JAVA_HOME

Note Amazon Linux already has JAVA_HOME set in /etc/profile.d/aws-apitools-common.sh.

Set the following in /etc/profile.d/java.sh

/etc/profile.d/java.sh

1
2
3
4
5
6
7
8
JRE_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")
JDK_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
if [ "/usr" != $JDK_HOME ]
then
    export JAVA_HOME=$JDK_HOME
else
    export JAVA_HOME=$JRE_HOME
fi

Parts of this series