linux is recommended for viewing jdk installed and uninstalling jdk

  • 2020-05-13 04:27:48
  • OfStack

1. View the installation path of Jdk:

whereis java
which java (java execution path)
echo $JAVA_HOME

echo $PATH

Note: if it is in windows, you can use:

set java_home: view the JDK installation path
java-version: view the JDK version

2. Uninstall the old version of JDK:

1. Determine the version of JDK:

rpm -qa | grep jdk

rpm -qa | grep gcj

The possible results are:

libgcj-4.1.2-42.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

2. Then uninstall:

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

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

1) uninstall the jdk version of the system:
Check out jdk:
#rpm -qa|grep gcj
You might see something like this:
libgcj-4.1.2-44.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Delete the search above using the rpm-e --nodeps command:
# rpm - e � nodeps java -- 1.4.2 -- gcj compat - 1.4.2.0-40 jpp. 115

2) uninstall the jkd version installed by rpm
View the installed jdk:
#rpm -qa|grep jdk
You might see something like this:
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

· execute the command at shell terminal./ uninstall.sh to uninstall jdk

3. Download the new version of JDK

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

4. Install JDK (take JDK1.6 as an example)

1. jdk1.6 provides the following two self-extracting files:
1) jdk u22 4-6 linux - i586. bin
2) jdk u22 4-6 linux - i586 - rpm. bin

2. I downloaded jdk-6u22-linux-i586-rpm. bin

3. Add executable permissions to all users
#chmod +x jdk-6u22-linux-i586-rpm.bin

4. Execute the file as follows:
#./jdk-6u22-linux-i586-rpm.bin
rpm packages are unzipped after execution, including jdk-6u22-linux-i586.rpm is the main package, and the next step is to install the main package.

5. Switch to root user, enter the directory where jdk-6u22-linux-i586.
rpm -ivh jdk-6u22-linux-i586.rpm
The installation software will automatically install JDK to /usr/java/ jdk-1.6.0 _22-fcs

When installing on linux, you will often encounter the following Fail:

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

Use this command:

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

5. Configure environment variables:

If all users want to share the environment variable for jdk, you can set it as follows.

(it's best not to do that, though. If there are other users using other JDK, they will be affected.)

Add the following in the /etc/profile document:
# 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: in order for the modified file to take effect immediately, run # source /etc/profile or it will only take effect the next time you reenter the user.

Remember to add $CLASSPATH to the CLASSPATH path: otherwise you may get an error when interpreting the class file.

You can also use a more radical approach: the reboot command to restart the machine.

Sometimes you may find that the environment variables configured in /etc/profile fail after the system is rebooted or the SSH connection is reused. The reason may be

1. Environment variables are in effect for a non-root user, but when you switch to root user, commands such as javac become invalid.

2. Environment variables written to /etc/profile will automatically take effect after reboot. Execute the source command as you described every time you open the terminal before restarting it.

Attachment: how to install tar type JDK:

First unzip *.tar.gz

tar-xzvf *. tar. gz assumes that the resulting folder is java

Move it to /usr/

sudo mv java /usr/local then set the environment variable:

sudo vim /etc/profile open the file

Enter at the end:

export JAVA_HOME = / usr/local/java export JRE_HOME = / usr/local/java/jre export CLASSPATH =. : $JAVA_HOME/lib: $JRE_HOME/lib: $CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATHUbuntu modify the default jdk

update alternatives - install/usr bin/java java/usr/localjava/bin/java 300 update - alternatives - install/usr/bin/javac javac/usr/local/java/bin/javac 300 adds the jdk we installed to the java menu in this 1 step.

update-alternatives --config java select the default jdk

java -version


Related articles: