I'm thinking about include 3 steps to uninstall a package on CentOS7 but stuck in merge 3 command of uninstall a package to only 1 command.

Okay, this is my situation: I have java package jdk-8u151-linux-x64.rpm which install successfully before, and I want to uninstall it.
Of course, I can not uninstall this java package using command :

# rpm -e jdk-8u151-linux-x64.rpm

So I have to using 3 command in 3 steps as below :

  • Step 1: I have to find the name of the package i install by :

    [susu@localhost ~]$ rpm -qip jdk-8u151-linux-x64.rpm
    [susu@localhost ~]$ rpm -qip jdk-8u151-linux-x64.rpm
    Name        : jdk1.8
  • Step 2: using this command to find exactly package are:

    [susu@localhost ~]$ sudo rpm -qa |grep -i 'jdk1.8'
    [sudo] password for susu: 
  • Step 3: using rpm -e to erase the package:

    rpm -e jdk1.8-1.8.0_151-fcs.x86_64

So my question is: how can I merge the command in Step 2 and Step 3 into only one command?

1 Answer 1


Query for the NVR and remove that.

rpm -e "$(rpm -qp --queryformat '%{name}-%{version}-%{release}' "$1")"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .