During installation of Java using rpm files I faced issues many times. After that i found a better way to install java from Sun site. Using below steps i have installed java successfully many times without facing any issues. We can also install multiple version of java easily if required. Oracle has also released Java 8. To install it read article Install Java 8 in CentOS, Redhat and Fedora.
Use following step by step instructions to install or update Java. I recommend to read carefully instruction for downloading Java from Linux command line.
Downloading Latest Java Archive
Java latest archive is available on its official site. We recommend to download latest version of Java from Oracle official website.
For 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/7u75-b13/jdk-7u75-linux-x64.tar.gz"
For 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/7u75-b13/jdk-7u75-linux-i586.tar.gz"
After completing download, Extract archive using following command. Use archive file as per your system configuration. For this example we are using CentOS 6.6 (64 bit) system.
# tar xzf jdk-7u75-linux-x64.tar.gz
Install Java with Alternatives
After extracting Java archive file, we just need to set up to use newer version of Java using alternatives. Use the following commands to do it.
# cd /opt/jdk1.7.0_75/ # alternatives --install /usr/bin/java java /opt/jdk1.7.0_75/bin/java 2 # alternatives --config java
There are 4 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java + 2 /opt/jdk1.7.0_60/bin/java 3 /opt/jdk1.7.0_72/bin/java 4
/opt/jdk1.7.0_75/bin/javaEnter to keep the current selection[+], or type selection number: 4[Press Enter]
Now you may also required to set up
# alternatives --install
/usr/bin/jarjar /opt/jdk1.7.0_75/bin/jar 2 # alternatives --install /usr/bin/javacjavac /opt/jdk1.7.0_75/bin/javac 2 # alternatives --set jar/opt/jdk1.7.0_75/bin/jar # alternatives --set javac/opt/jdk1.7.0_75/bin/javac
Check Installed Java Version
Use following command to check which version of Java is currently being used by system.
# java -version java version "
1.7.0_75" Java(TM) SE Runtime Environment (build 1.7.0_75-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)
Configuring Environment Variables
Most of Java based application’s uses environment variables to work. Use following commands to set up these variable properly. It’s also good to add following commands to any start-up script like ~/.bashrc or ~/.bash_profile.
- Setup JAVA_HOME Variable
# export JAVA_HOME=/opt/jdk1.7.0_75
# export JRE_HOME=/opt/jdk1.7.0_75/jre
# export PATH=$PATH:/opt/jdk1.7.0_75/bin:/opt/jdk1.7.0_75/jre/bin
I hope above steps will help you for installing Java on your Linux system. You can follow above steps to install multiple version of Java as same time but you can use only one version at a time.