How to Install Java Development Kit 6 on CentOS/RHEL

This post shows how to install and configure Java Development Kit 6 on CentOS/RHEL.

Download Java Development Kit 6

You can download JDK 6 versions from e.g. Oracle’s Java Webpage : oracle.com/java/technologies/javase-downloads.html

  • Select “Accept License Agreement”.
  • Then select “Linux self-extracting file” for Linux Platform.
  • Save the file “jdk-6-[xxxx]-linux-i586.bin” to e.g . /opt or

Install JDK or JRE

Install JDK or JRE by running the .bin file as shown below:

# cd /opt
# chmod +x jdk-6-linux-i586.bin
# ./jdk-6-linux-i586.bin
... ...
Do you agree to the above license terms? [yes or no]
yes

Set the environment variables

You can add the following lines to /etc/profile or .bash_profile file in your home directory. And then run “source /etc/profile” or “. .bash_profile” so that the environment variables can take effect.

$ export JAVA_HOME=/opt/jdk1.6.0
$ export PATH=$JAVA_HOME/bin:$PATH

Check the JDK version

Once you are done with the installation, you can check the JDK version with below command:

# java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)