[Linux] Use the apt command to delete/uninstall software packages under Ubuntu system

Everyone knows that when installing a new software package in ubuntu, just use sudo apt-get installthe command directly. So, what if you want to uninstall or delete a package?

1. Delete the software packages (including installed packages) that were installed to meet the dependencies but are no longer needed, and keep the configuration files (this command can easily cause the system to fail to enter the system desktop)

$ sudo apt-get autoremove 

High energy warning: use this command with caution! ! !

It will delete a lot of software that "it thinks" you no longer use without your knowledge.

If unfortunately there is a problem with this command, try to update the library and software, and you apt-get update && apt-get upgrade may solve the dependency version problem yourself, as long as it can get it. In addition, do not interrupt during the use of autoremove.

2. Delete the installed software package (keep the configuration file), will not delete the dependent software package, and keep the configuration file;

$ sudo apt-get remove 

3. Delete the installed software package (do not keep the configuration file), delete the software package, and delete the corresponding dependent software package.

$ sudo apt-get purge / sudo apt-get --purge remove 

4. Delete the installed software installation package, that is, automatically /var/cache/apt/archives/delete all the deb files, which is equivalent to cleaning the downloaded software installation package.

$ sudo apt-get clean 

5. Remove packages that were installed to satisfy some dependencies but are no longer needed.

$ sudo apt-get autoclean 

The underlying package of apt is dpkg, and when dpkg installs the package, it will *.debput the files /var/cache/apt/archives/in it; therefore, this command will delete the expired deb in this directory.

How to completely uninstall the software? Follow these steps:

sudo apt-get --purge remove <package>				# 删除软件及其配置文件
sudo apt-get autoremove <package>					# 删除没用的依赖包
sudo dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P		# 清理dpkg的列表中有“rc”状态的软件包

Supplement: Introduction to dpkg

dpkgUbuntu is a Debian-based Linux system, and the software of the Debian system is managed using APT . dpkgShort for "Debian Packager", it is a low-level software package management tool.

You can enter dpkg -lto view the status of the software, and enter dpkg -Pto uninstall the software. Because dpkg --removeit just deletes the installed files, but not the configuration files. Instead dpkg --purge, both the installation file and the configuration file are deleted.

Guess you like

Origin blog.csdn.net/Cappuccino_jay/article/details/125203753