This tutorial shows you how to install jdk7 on 32bit centOs, 64-bit system is similar.
1. check your java version, enter the following command:
>java -version
It shows something like this:
# java -version
java version "1.6.0_17"
OpenJDK Runtime Environment (IcedTea6 1.7.5) (rhel-1.31.b17.el6_0-i386)
OpenJDK Client VM (build 14.0-b16, mixed mode)
java version "1.6.0_17"
OpenJDK Runtime Environment (IcedTea6 1.7.5) (rhel-1.31.b17.el6_0-i386)
OpenJDK Client VM (build 14.0-b16, mixed mode)
2. Download JDK7 from oracle's official website(JDK7).
3. Change to root user.(Only root user can install software on Linux)..
>su
enter your root password, and run the JDK file.
>rpm -ivh /home/username/Desktop/jdk-7-linux-i586.rpm
It looks like this:
Preparing... ################################### [100%]
1:jdk ################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
4. Setup the environmental variables. We need to find out the "profile" file :
> cd ~
> vim /etc/profile
add the following lines at the bottom of the profile file:
export JAVA_HOME=/usr/java/jdk1.7.0
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
Save your changes and quit:
>:wq
restart your terminal or enter the following command to activate your changes:
> source /etc/profile
5. choose JDK version
If you use "java -version" to check the JDK version, it is still JDK6, we need to choose JDK7 which we just installed on centOs by "alternative" command
First, we need to install alternative :
then setup JDK:
> update-alternatives --config java
then it will show the following choises:
*+ 1 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
3 /usr/java/jdk1.7.0/bin/java
Press Enter to save your current choise, or enter number:3. Now we are almost done.
6. Verify your java version
> java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
It should work now.
Thanks a lot. It really helped and saved me from a lot of trouble... I messed my whole eclipse workspace on CentOS but it finally helped after two days of research :)
ReplyDelete