1. Uninstall openjdk
View the current system's JDK: rpm-Qa | grep JDK (I found here: java-1.6.0-openjdk-1.6.0.0-1.43.1.10.6.el6_2.i686), if not found, you can use rpm-Qa | grep gcj
Remove the built-in JDK: Yum-y remove java-1.6.0-openjdk-1.6.0.0-1.43.1.10.6.el6_2.i686 ,:
2. Install Sun JDK
Since I downloaded jdk-7-linux-i586.tar.gz, You can unzip it directly in the installation directory,
Go to/USR and run the tar-zxvf jdk-7-linux-i586.tar.gz. After decompression, you can see that a folder named jdk1.7.0 is added under the/usr directory.
3. Configure the environment
VI/etc/profile open the profile file and add it at the end of the profile file
JAVA_HOME=/usr/jdk1.7.0PATH=$JAVA_HOME/bin:$PATHCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JAVA_HOMEexport PATHexport CLASSPATH
Save and close the profile file, and run the source/etc/profile command to make the modification take effect (you can restart the system without executing this command)
In this way, JDK is successfully installed.
Test whether the installation is successful: run Java-version. The following result shows that the installation is successful.
[root@localhost ~]# java -versionjava 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)
If-Bash: [root command not found error please open the/etc/profile file and find something similar to the following (the following information is added when I installed the Oracle database, and the error lies in this one):
if [$USER = 'oracle']; then if [$SHELL = '/bin/ksh']; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fifi
Modify the preceding content:
if [ $USER = 'oracle' ]; then if [ $SHELL = '/bin/ksh' ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fifi
Error Cause Analysis: in fact, [and $ user need to be separated by spaces. When they are connected together, they become a variable such as [root, which is escaped. Therefore, after spaces are added, source/etc/profile is normal.