如何使用 apt 或 apt-get 删除行为异常的软件包?

如何使用 apt 或 apt-get 删除行为异常的软件包?

我正在尝试删除一个明显损坏的包gammu-smsd.service

当我运行时sudo apt remove gammu-smsd.service,我得到以下结果:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package gammu-smsd.service

我当时想删除这个包,因为在进行清理时,我在尝试安装和删除我选择的包时遇到了问题。这是升级的结果(更新没有问题)。

这是运行的结果sudo apt upgrade

Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Abort.

上面的输出结果中第 6 行提醒我出现了问题。当我得知罪魁祸首是时gammu-smsd.service,我运行了systemctl status gammu-smsd.service获得这个结果:

● gammu-smsd.service - SMS daemon for Gammu
     Loaded: bad-setting (Reason: Unit gammu-smsd.service has a bad unit file setting.)
     Active: inactive (dead)
       Docs: man:gammu-smsd(1)

Jul 18 20:15:18 LolouilaLawelima systemd[1]: /lib/systemd/system/gammu-smsd.service:9: Neither a valid executable name nor an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd

Jul 18 20:15:18 LolouilaLawelima systemd[1]: gammu-smsd.service: Unit configuration has fatal error, unit will not be started.

Jul 18 20:56:24 LolouilaLawelima systemd[1]: /lib/systemd/system/gammu-smsd.service:9: Neither a valid executable name nor an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd

Jul 18 20:56:24 LolouilaLawelima systemd[1]: gammu-smsd.service: Unit configuration has fatal error, unit will not be started.

Jul 18 20:56:25 LolouilaLawelima systemd[1]: /lib/systemd/system/gammu-smsd.service:9: Neither a valid executable name nor an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd

Jul 18 20:56:25 LolouilaLawelima systemd[1]: gammu-smsd.service: Unit configuration has fatal error, unit will not be started.

Jul 18 21:18:31 LolouilaLawelima systemd[1]: /lib/systemd/system/gammu-smsd.service:9: Neither a valid executable name nor an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd

Jul 18 21:18:31 LolouilaLawelima systemd[1]: gammu-smsd.service: Unit configuration has fatal error, unit will not be started.

Jul 18 21:18:33 LolouilaLawelima systemd[1]: /lib/systemd/system/gammu-smsd.service:9: Neither a valid executable name nor an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd

Jul 18 21:18:33 LolouilaLawelima systemd[1]: gammu-smsd.service: Unit configuration has fatal error, unit will not be started.

我如何删除或清除 apt 无法找到的包?

评论里的建议并运行sudo apt remove gammu-smsd, 我有:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libgammu-i18n libgammu8 libgsmsd8
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  gammu-smsd
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 179 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 737130 files and directories currently installed.)
Removing gammu-smsd (1.41.0-1) ...
Failed to stop gammu-smsd.service: Unit gammu-smsd.service not loaded.
invoke-rc.d: initscript gammu-smsd, action "stop" failed.
dpkg: error processing package gammu-smsd (--remove):
 installed gammu-smsd package pre-removal script subprocess returned error exit status 1
dpkg: too many errors, stopping
Failed to start gammu-smsd.service: Unit gammu-smsd.service has a bad unit file setting.
See system logs and 'systemctl status gammu-smsd.service' fo
r details.
invoke-rc.d: initscript gammu-smsd, action "start" failed.
● gammu-smsd.service - SMS daemon for Gammu
     Loaded: bad-setting (Reason: Unit gammu-smsd.service ha
s a bad unit file setting.)
     Active: inactive (dead)
       Docs: man:gammu-smsd(1)

Jul 18 23:16:57 LolouilaLawelima systemd[1]: /lib/systemd/sy
stem/gammu-smsd.service:9: Neither a valid executable name n
or an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd
Jul 18 23:16:57 LolouilaLawelima systemd[1]: gammu-smsd.serv
ice: Unit configuration has fatal error, unit will not be st
arted.
Jul 18 23:16:59 LolouilaLawelima systemd[1]: /lib/systemd/sy
stem/gammu-smsd.service:9: Neither a valid executable name n
or an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd
Jul 18 23:16:59 LolouilaLawelima systemd[1]: gammu-smsd.serv
ice: Unit configuration has fatal error, unit will not be st
arted.
Jul 18 23:22:08 LolouilaLawelima systemd[1]: /lib/systemd/sy
stem/gammu-smsd.service:9: Neither a valid executable name n
or an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd
Jul 18 23:22:08 LolouilaLawelima systemd[1]: gammu-smsd.serv
ice: Unit configuration has fatal error, unit will not be st
arted.
Jul 18 23:22:11 LolouilaLawelima systemd[1]: /lib/systemd/sy
stem/gammu-smsd.service:9: Neither a valid executable name n
or an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd
Jul 18 23:22:11 LolouilaLawelima systemd[1]: gammu-smsd.serv
ice: Unit configuration has fatal error, unit will not be st
arted.
Jul 18 23:22:12 LolouilaLawelima systemd[1]: /lib/systemd/sy
stem/gammu-smsd.service:9: Neither a valid executable name n
or an absolute path: ${CMAKE_INSTALL_FULL_BINDIR}/gammu-smsd
Jul 18 23:22:12 LolouilaLawelima systemd[1]: gammu-smsd.serv
ice: Unit configuration has fatal error, unit will not be st
arted.
dpkg: error while cleaning up:
 installed gammu-smsd package post-installation script subpr
ocess returned error exit status 1
Errors were encountered while processing:
 gammu-smsd
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

答案1

似乎有一个针对此问题打开了错误并且它在下一个版本中被修复了,但由于某种原因,它还没有发布 20.04,因此运行以下命令来修复该问题:

sudo sed -i 's|${CMAKE_INSTALL_FULL_BINDIR}|/usr/bin|g' /lib/systemd/system/gammu-smsd.service

最后,重新加载 systemd 并重新启动服务:

sudo systemctl daemon-reload
sudo systemctl restart gammu-smsd

解释:

问题似乎已在您的错误中指出。错误指出文件第 9 行指示的路径/lib/systemd/system/gammu-smsd.service未定义。

因此,要找到的路径gammu-smsd,您可以使用命令which gammu-smsd

然后,您只需要编辑文件并用绝对路径/lib/systemd/system/gammu-smsd.service替换变量,这就是上面的命令所做的。${CMAKE_INSTALL_FULL_BINDIR}/usr/binsed

相关内容