1. OpenJDK is installed by default in the JDKCentos system of the query system. we recommend that you install sun's JDK. First, check whether the system has jdk installed and the OpenJDK version. if so, uninstall the system and install the jdk Version of sun. Run the following command to check whether OpenJDK has been installed: # rpm-qa | grepjav 1. query the system by default: JDK
OpenJDK is installed in Centos by default. we recommend that you install sun's JDK. First, check whether the system has jdk installed and the OpenJDK version. if so, uninstall the system and install the jdk Version of sun.
Run the following command to check whether OpenJDK is installed in the query system:
# Rpm-qa | grep java
# Rpm-qa | grep jdk
# Rpm-qa | grep gcj
Query the current java version:
As shown above,
OpenJDK 1.7.0 _ 65 is installed in the system.
2. delete the installed OpenJDK
To delete the installed OpenJDK, run the following command:
Others rpm-e jdk related (General delete command: delete a specific package. If dependency exists, it cannot be deleted)
Rpm-e-nodeps jdk related (force delete command, ignore dependency, delete a specific package. If the preceding command is used to delete other dependent files, you can use this command to forcibly delete them)
Note: jdk-related files refer to the jdk-related files found using the query command in the previous step.
If you use rpm to force delete the command, as follows:
# Rpm e java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.i686
# Rpm e tzdata-java-2014e-1.el6.noarch
When executing the rpm query command, no jdk file is found, indicating that jdk has been deleted successfully.
Next, to ensure that the jdk has been completely deleted, run the query command # find/-name jdk: it can be seen that the query fails, indicating that the jdk has been deleted.
If any of the directories involved are found, you can use the # rm-rf directory to delete the residual directories one by one.
So far, jdk deletion has been completed.
3. download and install JDK
1) Download jdk
Baidu cloud disk Download: http://pan.baidu.com/s/1c0IlL0O
There are different versions available on the network disk, download as needed, because I use the system is 32-bit, so download the 32-bit jdk Version: jdk-6u45-linux-i586.bin.
If you use Windows for download, you can use SecureCRT terminal tool to log on to the Centos system, and then upload the installation package in the local Windows system to the Centos system through SFTP.
After the installation package is uploaded, it is stored in the/software directory under the root directory:
2) install JDK
With the jdk installation package, you can install it.
A. create a new java directory under the/usr directory, and put the installation package in the/usr/java Directory: view the file execution permission: you can see that the current user has the execution permission, so you do not need to modify the file permission.
Next, run the installation with the #./jdk-6u45-linux-i586.bin command, because the execution process has many texts, only the following parts are listed:
3) configure environment variables
After installation, you must configure jdk environment variables.
Modify the/etc/profile file and add the following information at the end:
JAVA_HOME =/usr/java/jdk1.6.0 _ 45
PATH = $ PATH: $ JAVA_HOME/bin
CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar
Export JAVA_HOME PATH CLASSPATH
Save and exit.
To make the/etc/profile file take effect immediately after modification, run the following command:
Command: #./etc/profile
Note: There is a space between. and/etc/profile.
4. test JDK
After the environment variables are installed and configured, test whether the jdk is correctly installed.
Enter java-version or javac-version. if the version information is displayed, the installation is successful:
As shown above, jdk has been installed successfully. Next we will test a simple Hello World program.
A. create a hello. java file.
B. add the following code:
Save and exit.
C. compile and run:
As can be seen from the above, jdk compilation and running are normal.
So far, jdk installation has been successfully completed.