#
Uninstall Java 17 from Linux (CentOS 8)
There are two ways to uninstall Java. Please use the method that you used when you installed Java:
- if you used RPM to install Java, then use the RPM uninstall method
- if you unzipped a tar file, you can simply remove the directory where Java was installed.
#
See if Java is installed using RPM
rpm -aq | grep openjdk
or
rpm -aq | grep jdk
If you see something like
[root@linux1 ~]# rpm -aq | grep openjdk
java-17-openjdk-17.0.5.0.8-2.el8.x86_64
java-17-openjdk-devel-17.0.5.0.8-2.el8.x86_64
java-17-openjdk-headless-17.0.5.0.8-2.el8.x86_64
it means that java is installed by RPM. In this case Java will be uninstalled using rpm
.
#
Uninstall Java 17 from Linux (CentOS 8) using RPM
For this we need to run the following command:
rpm -e java-17-openjdk-devel
rpm -e java-17-openjdk
rpm -e java-17-openjdk-headless
You can also remove Java from Linux (CentOS 8) using dnf
command:
dnf -y remove java-17-openjdk java-17-openjdk-devel
When you run this command you will see something like this:
[root@linux1 ~]# dnf -y remove java-17-openjdk java-17-openjdk-devel
Dependencies resolved.
======================================================================================
Package Arch Version Repository Size
======================================================================================
Removing:
java-17-openjdk x86_64 1:17.0.5.0.8-2.el8 @appstream 1.2 M
java-17-openjdk-devel x86_64 1:17.0.5.0.8-2.el8 @appstream 8.9 M
Removing unused dependencies:
copy-jdk-configs noarch 4.0-2.el8 @appstream 19 k
java-17-openjdk-headless x86_64 1:17.0.5.0.8-2.el8 @appstream 196 M
javapackages-filesystem noarch 5.3.0-1.module_el8.0.0+11+5b8c10bd @appstream 1.9 k
lksctp-tools x86_64 1.0.18-3.el8 @baseos 252 k
ttmkfdir x86_64 3.0.9-54.el8 @appstream 140 k
tzdata-java noarch 2022d-1.el8 @appstream 346 k
xorg-x11-fonts-Type1 noarch 7.5-19.el8 @appstream 863 k
Transaction Summary
======================================================================================
Remove 9 Packages
Freed space: 207 M
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Erasing : java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64 1/9
Running scriptlet: java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64 1/9
Erasing : java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64 2/9
Running scriptlet: java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64 2/9
Erasing : xorg-x11-fonts-Type1-7.5-19.el8.noarch 3/9
Running scriptlet: xorg-x11-fonts-Type1-7.5-19.el8.noarch 3/9
Erasing : java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64 4/9
Running scriptlet: java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64 4/9
Erasing : copy-jdk-configs-4.0-2.el8.noarch 5/9
Erasing : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd 6/9
Erasing : tzdata-java-2022d-1.el8.noarch 7/9
Erasing : lksctp-tools-1.0.18-3.el8.x86_64 8/9
Running scriptlet: lksctp-tools-1.0.18-3.el8.x86_64 8/9
Erasing : ttmkfdir-3.0.9-54.el8.x86_64 9/9
Running scriptlet: ttmkfdir-3.0.9-54.el8.x86_64 9/9
Verifying : copy-jdk-configs-4.0-2.el8.noarch 1/9
Verifying : java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64 2/9
Verifying : java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64 3/9
Verifying : java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64 4/9
Verifying : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd 5/9
Verifying : lksctp-tools-1.0.18-3.el8.x86_64 6/9
Verifying : ttmkfdir-3.0.9-54.el8.x86_64 7/9
Verifying : tzdata-java-2022d-1.el8.noarch 8/9
Verifying : xorg-x11-fonts-Type1-7.5-19.el8.noarch 9/9
Removed:
copy-jdk-configs-4.0-2.el8.noarch
java-17-openjdk-1:17.0.5.0.8-2.el8.x86_64
java-17-openjdk-devel-1:17.0.5.0.8-2.el8.x86_64
java-17-openjdk-headless-1:17.0.5.0.8-2.el8.x86_64
javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch
lksctp-tools-1.0.18-3.el8.x86_64
ttmkfdir-3.0.9-54.el8.x86_64
tzdata-java-2022d-1.el8.noarch
xorg-x11-fonts-Type1-7.5-19.el8.noarch
Complete!
Warning
The removal of Java was done under the root account, but generally another user is used in order to avoid the over utilization of the root account. This account must be defined as a sudoer user.
#
Remove Java when installed from a tar file
If you unzipped a tar file when installed, you can simply remove the directory where Java was installed.
Info
Also, be aware that some environment variable might be modified or removed (for example, JAVA_HOME, PATH).
Here are some related articles: