Prepare
Under normal circumstances, we have to uninstall the OPENJDK that comes with Linux, and then install the SUN JDK.
First, uninstall the built-in java
Check whether the JDK that comes with Linux is installed.
Enter the following command to view the installed Java version information.
java -version
Enter the following command to view JDK information.
rpm -qa|grep java
As shown below.
Uninstall the installed JAVA as shown below.
Uninstallation is complete, as shown in the figure below.
Uninstall the other one as shown below.
Uninstallation is complete, as shown in the figure below.
The second step is to install SUN's JDK.
Official website: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Create a java directory under /usr, in order to install java programs in this directory, enter the following command:
mkdir /usr/java
Copy the downloaded installation file to the shared folder share of the original system, and view the file through the command:
cd /mnt/share
ls -a
Copy the file to the /usr/java directory and enter the following command:
cp *.gz /usr/java
View the /usr/java directory and enter the following command:
cd /usr/java
ls -a
Unzip the file and enter the following command: Linux code
tar -xzvf jdk-7u13-linux-x64.gz
After decompression, a new directory jdk1.7.0_13 will be generated in the /usr/java directory, which stores the decompressed files. For the convenience of future settings, we should rename the generated directory jdk1.7.0_13 to jdk, and enter the following command:
mv jdk1.7.0_13 jdk
Or, if the file you downloaded is in rpm format, replace the tar command above with the following command to install, and other steps remain unchanged.
rpm -ivh jdk-7u13-linux-x64.rpm
Finally, set the environment variables. Enter the following command to enter the configuration file, or open the configuration file by other means.
vi /etc/profile
Enter the configuration file, as shown in the figure below, delete the first line below and replace it with the configuration information in the following 2-4 lines.
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
export JAVA_HOME=/usr/local/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Make environment variables take effect. Execute the configuration file to make it take effect immediately, enter the following command:
source /etc/profile
To verify that the installation was successful, enter the following command:
Java -version