dpkg
列出系统已安装的所有软件包
dpkg -l
查询系统中是否安装某软件包
查询 PostgreSQL
dpkg -l | grep -i postgre
查询某软件包的安装目录
dpkg -L postgresql
注意:软件包名只能精确匹配
apt-get
卸载软件包
apt-get remove
apt-get purge
apt-get remove --purge
第二条和第三条等同
purge 和 remove 的区别是:remove 不删除配置文件,而 purge 删除配置文件,当然自定义的目录,purge 也删除不了,需要自己手动删除。
案例:卸载 PostgreSQL
1. 查询出 PostgreSQL 相关的软件包
单纯的用 apt-get remove postgresql 只会卸载一个包
~$ dpkg -l | grep -i postgresql
ii libpq5 9.1.13-0ubuntu0.12.04 PostgreSQL C client library
ii postgresql 9.1+129ubuntu1 object-relational SQL database (supported version)
ii postgresql-9.1 9.1.13-0ubuntu0.12.04 object-relational SQL database, version 9.1 server
ii postgresql-client 9.1+129ubuntu1 front-end programs for PostgreSQL (supported version)
ii postgresql-client-9.1 9.1.13-0ubuntu0.12.04 front-end programs for PostgreSQL 9.1
ii postgresql-client-common 129ubuntu1 manager for multiple PostgreSQL client versions
ii postgresql-common 129ubuntu1 PostgreSQL database-cluster manager
ii postgresql-contrib 9.1+129ubuntu1 additional facilities for PostgreSQL (supported version)
ii postgresql-contrib-9.1 9.1.13-0ubuntu0.12.04 additional facilities for PostgreSQL
ii postgresql-doc 9.1+129ubuntu1 documentation for the PostgreSQL database management system
ii postgresql-doc-9.1 9.1.13-0ubuntu0.12.04 documentation for the PostgreSQL database management system
2. 用 apt-get purge 卸载相关软件包
~$ sudo apt-get purge postgresql postgresql-9.1 postgresql-client \
> postgresql-client-9.1 postgresql-client-common postgresql-common postgresql-contrib \
> postgresql-contrib-9.1 postgresql-doc postgresql-doc-9.1
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
postgresql* postgresql-9.1* postgresql-client* postgresql-client-9.1*
postgresql-client-common* postgresql-common* postgresql-contrib* postgresql-contrib-9.1*
postgresql-doc* postgresql-doc-9.1*
0 upgraded, 0 newly installed, 10 to remove and 6 not upgraded.
After this operation, 28.1 MB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 69141 files and directories currently installed.)
Removing postgresql ...
Removing postgresql-contrib ...
Removing postgresql-contrib-9.1 ...
Removing postgresql-9.1 ...
* Stopping PostgreSQL 9.1 database server [ OK ]
Purging configuration files for postgresql-9.1 ...
Dropping cluster main...
Removing postgresql-client ...
Removing postgresql-client-9.1 ...
Removing postgresql-common ...
Removing 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Purging configuration files for postgresql-common ...
Removing postgresql-client-common ...
Purging configuration files for postgresql-client-common ...
Removing postgresql-doc ...
Removing postgresql-doc-9.1 ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
$ dpkg -l | grep -i postgresql
ii libpq5 9.1.13-0ubuntu0.12.04 PostgreSQL C client library
3. 相关目录
ls /var/lib/postgresql
ls /var/log/postgresql
ls /etc/postgresql
已经被删除
参考资料
dpkg
What is the Difference Between `apt-get purge` and `apt-get remove`?
What is the correct way to completely remove an application?
How to remove Postgres from my installation?