Uninstalling and installing JDK under Linux

uninstall

1. Delete the JDK that comes with Linux

Step 1: First check how many JDKs come with Linux, use the command:

rpm -qa | grep -i java

Insert image description here

Step 2: Delete JDK and execute the command:

rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
#rpm -qa:查询所安装的所有rpm包
#grep -i:忽略大小写
#xargs -n1:表示每次只传递一个参数
#rpm -e --nodeps:强制卸载软件

Step 3: Edit the profile file and remove the environment variable configuration

vim /etc/profile
#然后 source命令让修改后的profile文件立即生效
source /etc/profile

at last:

#查看是否还在即可
rpm -qa | grep -i java
#或者查看java版本
java -version

2. Uninstall the JDK installed by yourself on Linux

Step 1: First enter java -version to check whether JDK is installed

java -version

Step 2: Check the path of jdk installation

which java

Step 3: Uninstall the command rm -rf JDK address. For example, my installation directory is /usr/java/jdk1.8.0_181/

rm -rf /usr/java/jdk1.8.0_181/

Step 4: Go to the /usr/java directory to see if the file still exists

cd /usr/java/
ls

Step 5: Next delete the environment variables

vim /etc/profile

Remove the following code:
Insert image description here

#然后 source命令让修改后的profile文件立即生效
source /etc/profile

Install

1. Install jdk using yum

Step 1: Check the installable java version

yum -y list java*

Insert image description here

Part 2: Choose a JDK version you want. Here I choose java-11-openjdk.x86_64

yum install -y java-11-openjdk.x86_64

Step 3: Check the JDK version after successful installation

java -version

Insert image description here
If you want to know where jdk is installed, you can use the following command:

rpm -ql java-11-openjdk.x86_64

Insert image description here
If the java command does not take effect after successful installation, you need to modify the environment variables.

vim /etc/profile

Add the following parameters
Insert image description here

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.18.0.10-1.el7_9.x86_64
export JRE_HOME=/usr/lib/jvm/java-11-openjdk-11.0.18.0.10-1.el7_9.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin

Then source the command to make the modified profile file take effect immediately.

source /etc/profile

2. Custom installation of JDK

Step 1: Download the JDK installation package

Oracle official website download address
Insert image description here
The editor here chose the version of jdk-11.0.17_linux-x64_bin.tar.gz Java11
Insert image description here
Insert image description here

Step 2: Put the downloaded file into the specified folder. Here I put it under /usr/java. You can choose the directory you like.

Insert image description here
The folder here already exists. If it is not there, create it.

cd /usr/
mkdir java

Step 3: Unzip the file

# tar包进行解压
tar -zxvf dk-11.0.17_linux-x64_bin.tar.gz

After decompressing the file, you will get a folder called jdk-11.0.17

Step 4: Modify environment variables

vim /etc/profile

Insert image description here
Just change the above address to the decompressed address.

at last

#刷新配置文件
source /etc/profile
#查看Java版本
java -version

Insert image description here

3. rpm installation jdk

Step 1: Download the rpm installation package from the official website

Oracle official website download address
Insert image description here

Part 2: Installation

rpm -ivh jdk-11.0.17_linux-x64_bin.rpm
# 通常默认安装是在/usr/java目录下 如果不在的话使用find命令查找一下
find /-name jdk-11.0.17*

Step 3: Configure environment variables

vim /etc/profil

Step 4: Refresh environment variables

#刷新配置文件
source /etc/profile
#查看Java版本
java -version

Guess you like

Origin blog.csdn.net/weixin_42600175/article/details/130086074