In general, we need to uninstall the openjdk that comes with Linux, and then install the Sun JDK.
First, check whether the JDK that comes with Linux is installed.
Run the following command to view the installed Java version.
Run the following command to view the JDK information.
As shown in.
Uninstall installed Java, as shown in.
The uninstall is completed, as shown in.
Detach another one, as shown in.
The uninstall is completed, as shown in.
Step 2: Install Sun's JDK.
Official Website: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Create a Java directory under/usr to install the Java program in this directory. Enter the following command:
Linux code mkdir/usr/Java
Copy the downloaded installation file to the share folder of the original system and run the following command to view the file:
Linux code
- CD/mnt/share
- Ls-
cd /mnt/sharels -a
Copy the file to the/usr/Java directory and enter the following command:
Linux code
- Cp *. GZ/usr/Java
cp *.gz /usr/java
Run the following command to view the/usr/Java directory:
Linux code
- CD/usr/Java
- Ls-
cd /usr/javals -a
As shown in.
Decompress the file and enter the following command:
Linux code
- Tar-xzvf jdk-7u13-linux-x64.gz
tar -xzvf jdk-7u13-linux-x64.gz
After decompression, a new directory jdk1.7.0 _ 13 will be generated under the/usr/Java Directory, which stores the decompressed files.
For later setup convenience, we changed the directory jdk1.7.0 _ 13 to JDK. Enter the following command:
Linux code
- MV jdk1.7.0 _ 13 JDK
mv jdk1.7.0_13 jdk
As shown in.
Alternatively, if the downloaded file is in RPM format, replace the tar command with the following command to install it. The other steps remain unchanged.
Linux code
- Rpm-IVH jdk-7u13-linux-x64.rpm
rpm -ivh jdk-7u13-linux-x64.rpm
Finally, set the environment variables.
Enter the following command to enter the configuration file.
Linux code
- VI/etc/profile
vi /etc/profile
As shown in.
Go to the configuration file, as shown in. Delete the first line in the red box and change the configuration information of the following three lines.
Make environment variables take effect.
Execute the configuration file to make it take effect immediately. Enter the following command:
Linux code
- Source/etc/profile
source /etc/profile
Run the following command to verify whether the installation is successful:
Linux code
- Java-version
Java -version
As shown in, the installation is successful!
Run the first Java program.
Create a new helloworld. Java file, as shown in.
Edit the file, as shown in.
Save the file, compile and run it, as shown in.
Running successful!
Java: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Centos6.5 install jdk1.7 for detailed steps