手动删除先前安装的应用程序的文件夹后,apt-get 不再起作用

手动删除先前安装的应用程序的文件夹后,apt-get 不再起作用

我整个周末都在努力将现有的 postgresql 数据库从版本 8.4 升级到 9.1。将操作系统从 10.0.4 更新到 12.04 后,我拥有两个版本的数据库。

我终于恼火了,在一时判断失误的情况下,我强行从我的机器中删除了所有与 8.4 相关的文件,使用如下命令:

find / -type d -name 8.4 2>/dev/null | xargs rm -rf {}

我认为删除它的更好方法是“apt-get remove postgresql-8.4”

当我尝试这样做时,apt-get 报告:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  postgresql-8.4
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 15.5 MB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 304184 files and directories currently installed.)
Removing postgresql-8.4 ...
find: `/usr/share/postgresql/8.4/tsearch_data': No such file or directory
dpkg: error processing postgresql-8.4 (--remove):
 subprocess installed pre-removal script returned error exit status 1
Errors were encountered while processing:
 postgresql-8.4
E: Sub-process /usr/bin/dpkg returned an error code (1)

如何从我的机器中清除 postgresql 8.4?

[[编辑]]

我尝试之后apt-get install --reinstall postgresql-8.4,出现以下错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  oidentd ident-server
The following NEW packages will be installed:
  postgresql-8.4
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 0 B/5,599 kB of archives.
After this operation, 15.5 MB of additional disk space will be used.
Selecting previously unselected package postgresql-8.4.
(Reading database ... 304010 files and directories currently installed.)
Unpacking postgresql-8.4 (from .../postgresql-8.4_8.4.14-0ubuntu12.04.2_amd64.deb) ...
Setting up postgresql-client-8.4 (8.4.14-0ubuntu12.04.2) ...
update-alternatives: error: alternative path /usr/share/postgresql/8.4/man/man1/psql.1.gz doesn't exist.
dpkg: error processing postgresql-client-8.4 (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of postgresql-8.4:
 postgresql-8.4 depends on postgresql-client-8.4; however:
  Package postgresql-client-8.4 is not configured yet.
dpkg: error processing postgresql-8.4 (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 postgresql-client-8.4
 postgresql-8.4
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

好的,这真的非常糟糕,因为其中有一个依赖嵌套,通过通常的 apt-get purge、apt-get -f install 等操作是无法消除的。解决这个问题的唯一方法(我在虚拟机中重现了你的问题并进行了测试)就是在那里放一个目录,让 apt 首先将其清除。

root@yourbox:/# mkdir -p /usr/share/postgresql/8.4/tsearch_data
root@yourbox:/# apt-get purge postgresql-8.4
root@yourbox:/# apt-get autoremove

由于那里有一个空目录可供 apt 删除,因此在我的虚拟机中,父包的初始清除和子包的自动删除均顺利完成。

答案2

因此,鉴于简单的解决方案不起作用,这里有一个需要更多工作和解释但成功率更高的解决方案。

apt 目前对您的 postgres 软件包非常困惑。困惑程度甚至到了我们需要让它更加困惑的程度。

安装/删除软件包时,可以运行某些脚本,这些是安装后、安装前等脚本,并且位于 中/var/lib/dpkg/info。为了使删除工作即使由于您弄乱了系统而导致这些脚本失败,您可以在每个受影响的软件包脚本的第一行后面添加一行exit 0。不要编辑其他脚本。

就 apt 而言,删除操作apt-get remove --purge将起作用,但这会留下一些混乱。要消除这些混乱,您应该使用经过阉割的 postrm/prerm 脚本重新安装您删除的软件包,并这次正确删除它们。

答案3

您最好先重新安装 8.4:

sudo apt-get install --reinstall postgresql-8.4

然后你可以用它删除

sudo apt-get remove --purge postgresql-8.4

如果重新安装失败,请向我们显示错误。

答案4

要删除 postgresql 并从头开始,这对我有用:
列出所有已安装的 postgresql 包。

dpkg -l | grep post  

然后 apt-get purge 上述命令返回的所有 postgresql 包:
例如:

apt-get purge postgresql postgresql-client postgresql-client-common postgresql-common postgresql-contrib postgresql-9.6 postgresql-client-9.6 postgresql-contrib-9.6  

相关内容