In this tutorial, we will show you how to install Java JDK 8 on CentOS 6. There are many programs and scripts that require java to run, but usually, Java is not installed by default on VPS or Dedicated Server. This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges.
Prerequisites
- A server running one of the following operating systems: CentOS 6.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Java JDK 8 on CentOS 6
Step 1. Remove the Java 1.6 or 1.7 that have been installed already, you can uninstall them using the following commands.
yum remove java-1.6.0-openjdk yum remove java-1.7.0-openjdk
Step 2. Downloading the latest Java archive.
Download the latest Java SE Development Kit 8 release from its official download page or use the following commands to download from the shell:
### CentOS 64-Bit ### cd /opt/ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u40-b25/jdk-8u40-linux-x64.tar.gz" tar xzf jdk-8u40-linux-x64.tar.gz
### CentOS 32-Bit ### cd /opt/ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u40-b25/jdk-8u40-linux-i586.tar.gz" tar xzf jdk-8u40-linux-i586.tar.g
Step 3. Install JAVA using alternatives.
After extracting the archive file use the alternatives command to install it. alternatives command is available in chkconfig
package:
# cd /opt/jdk1.8.0_40/ # alternatives --install /usr/bin/java java /opt/jdk1.8.0_40/bin/java 2 # alternatives --config java There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /opt/jdk1.8.0/bin/java + 2 /opt/jdk1.8.0_25/bin/java 3 /opt/jdk1.8.0_40/bin/java Enter to keep the current selection[+], or type selection number: 3
At this point, JAVA 8 has been successfully installed on your system. We also recommend to set up the javac and jar commands path using alternatives:
alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_40/bin/jar 2 alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_40/bin/javac 2 alternatives --set jar /opt/jdk1.8.0_40/bin/jar alternatives --set javac /opt/jdk1.8.0_40/bin/javac
Step 4. Verify the Installed Java version.
$ java -version java version "1.8.0_40" Java(TM) SE Runtime Environment (build 1.8.0_40-b25) Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
Step 5. Setup global environment variables.
We can easily set the environment variables using the export command as shown below:
Setup JAVA_HOME Variable:
export JAVA_HOME=/opt/jdk1.8.0_40
Setup JRE_HOME Variable:
export JRE_HOME=/opt/jdk1.8.0_40/jre
Setup PATH Variable:
export PATH=$PATH:/opt/jdk1.8.0_40/bin:/opt/jdk1.8.0_40/jre/bin
Congratulations! You have successfully installed Java. Thanks for using this tutorial for installing Oracle Java (JDK) 8 on CentOS 6 system. For additional help or useful information, we recommend you check the official Java website.