Uninstalling a failed dpkg package

Uninstalling a failed dpkg package

You may have experience install a broken package that you want to uninstall. If you uninstall with command

dpkg -r file_name.deb

You will get an error:

root@7b63e2627d93:/var/lib/ghost/content# dpkg -r dpkg-git_latest.deb                                                                                                      
dpkg: error: you must specify packages by their own names, not by quoting the names of the files they come in

To uninstall, you need to know the exact name of the debian package, by listing out them:

root@7b63e2627d93:/var/lib/ghost/content# dpkg -l '*git*'                                                                                                                  
Desired=Unknown/Install/Remove/Purge/Hold                                                                                                                                  
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend                                                                                             
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)                                                                                                                 
||/ Name           Version      Architecture Description                                                                                                                   
+++-==============-============-============-================================================                                                                              
iU  dpkg-git       1.1          all          Installs a debian package from a git source repo                                                                              
un  git-core       <none>       <none>       (no description available)   

dpkg-git is the debian package name and you can uninstall it by:

root@7b63e2627d93:/var/lib/ghost/content# dpkg -r dpkg-git                                                                                                                 
(Reading database ... 6585 files and directories currently installed.)                                                                                                     
Removing dpkg-git (1.1) ...