How to Use yum to install and uninstall jdk and use yum to uninstall jdk

Source: Internet
Author: User

How to Use yum to install and uninstall jdk and use yum to uninstall jdk

The installed CentOS comes with OpenJdk and uses the java-version command. The following information is displayed:

Java version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)

It is best to uninstall openjdk first and install the jdk of sun.

Check rpm-qa | grep java first

The following information is displayed:

Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

Uninstall:

Rpm-e -- nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Rpm-e -- nodeps java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

There are other commands

Rpm-qa | grep gcj

Rpm-qa | grep jdk

If openjdk source cannot be found, you can uninstall it like this.

Yum-y remove java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Yum-y remove java java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

Yes

1. view the Jdk installation path:

 

Whereis java
Which java (java execution path)
Echo $ JAVA_HOME

Echo $ PATH

 

Note: For windows, you can use:

Set java_home: view the JDK installation path
Java-version: view the JDK version.

 

2. Uninstall the old JDK version:

 

1. Determine the JDK version:

Rpm-qa | grep jdk

Rpm-qa | grep gcj

 

Possible results:

Libgcj-4.1.2-42.el5
Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

 

2. Uninstall:

Yum-y remove java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

If this method does not work, you can use the following method to uninstall it:

 

1) uninstall the built-in jdk version: 
View the built-in jdk:
# Rpm-qa | grep gcj
You may see the following similar information:
Libgcj-4.1.2-44.el5
Java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Run the rpm-e -- nodeps command to delete the content found above:
# Rpm-e-nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

2) uninstall the jkd version installed by rpm 
View the installed jdk:
# Rpm-qa | grep jdk
You may see the following similar information:
Jdk-1.6.0_22-fcs
Uninstall:
# Rpm-e -- nodeps jdk-1.6.0_22-fcs

 

3) Find the _ uninst subdirectory of the jdk installation directory.

· Run the command./uninstall. sh on the shell terminal to uninstall jdk.

 

3. download the new JDK version

Official Address: http://www.oracle.com/technetwork/java/javase/downloads/index.htm

 

4. Install JDK (taking JDK 1.6 as an example)

1. jdk1.6 provides the following two types of self-extracting files:
1) jdk-6u22-linux-i586.bin
2) jdk-6u22-linux-i586-rpm.bin
2. I downloaded a jdk-6u22-linux-i586-rpm.bin.
3. Add executable permissions to all users
# Chmod + x jdk-6u22-linux-i586-rpm.bin
4. Run the following command to execute the file:
#./Jdk-6u22-linux-i586-rpm.bin
Some rpm packages will be decompressed after execution, with a jdk-6u22-linux-i586.rpm which is the main package, followed by installing this main package.
5. Switch to the root user, enter the jdk-6u22-linux-i586.rpm directory, execute the following command:
Rpm-ivh jdk-6u22-linux-i586.rpm
The installation software automatically installs JDK under the/usr/java/jdk-1.6.0_22-fcs directory

During linux installation, the following Fail is often encountered:

RPM shocould not be used directly install RPM packages, use Alien instead!

Then run the following command:

Rpm-ivh jdk-6u22-linux-i586.rpm -- nodeps -- force

 

5. Configure environment variables:

If you want to share the jdk environment variables, you can set them as follows.

(But it is recommended that you do not use this method unless other users use another JDK .)
Add the following to the/etc/profile file:
# Vi/etc/profile
Export JAVA_HOME =/usr/java/jdk-1.6.0_22-fcs
Export CLASSPATH = $ CLASSPATH: $ JAVA_HOME/lib: $ JAVA_HOME/jre/lib
Export PATH = $ JAVA_HOME/bin: $ JAVA_HOME/jre/bin: $ PATH: $ HOME/bin

Note: to change the file to take effect immediately, run # source/etc/profile. Otherwise, it will only take effect the next time you re-enter the user.
Remember to add $ classpath to the classpath path: otherwise, an error may be reported when the class file is interpreted and executed.

Of course, you can also use the more thorough method: reboot command to restart the machine.

 

Sometimes you may find that the environment variables configured in/etc/profile are invalid after the system is restarted or the SSH connection is used again.

1. The environment variable of a non-root user takes effect, but after switching to the root user, the javac and other commands fail.

2.The environment variables written to/etc/profile automatically take effect after the restart. Run the source command every time you open the terminal before restarting.

 

Appendix: how to install JDK of the tar type:

 

First decompress * .tar.gz

tar -xzvf *.tar.gz

Assume that the obtained folder is java

Move it to/usr/

sudo mv java /usr/local

Then set the environment variable:

sudo vim /etc/profile

Open a file

Enter at the end:

export JAVA_HOME=/usr/local/javaexport JRE_HOME=/usr/local/java/jre export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATHexport PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

In this step, add the installed jdk to the java menu.

update-alternatives --config java

Select the default jdk

java -version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.