如何在 Ubuntu 上修復損壞的軟體包
我有一台 Ubuntu 18.10 伺服器,最近嘗試更新
git
. 我不斷收到許多軟體包未正確安裝的錯誤。Errors were encountered while processing: libpaper1:amd64 libpaper-utils unattended-upgrades libgs9:amd64 ghostscript
然後我跑了
dpkg --configure -a
,看到了同樣的錯誤。我要小心,不要給我的系統灌水,但我該如何解決這些錯誤?~ $ sudo apt list --upgradable Listing... Done ~ $ sudo apt-get check Reading package lists... Done Building dependency tree Reading state information... Done ~ $ sudo apt-get check Reading package lists... Done Building dependency tree Reading state information... Done ~ $ sudo apt-get upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 5 not fully installed or removed. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] y Setting up libpaper1:amd64 (1.1.24+nmu5ubuntu1) ... dpkg: error processing package libpaper1:amd64 (--configure): installed libpaper1:amd64 package post-installation script subprocess returned error exit status 10 dpkg: dependency problems prevent configuration of libpaper-utils: libpaper-utils depends on libpaper1; however: Package libpaper1:amd64 is not configured yet. dpkg: error processing package libpaper-utils (--configure): dependency problems - leaving unconfigured Setting up unattended-upgrades (1.5ubuntu3.18.10.4) ... dpkg: error processing package unattended-upgrades (--configure): installed unattended-upgrades package post-installation script subprocess returned error exit status 10 dpkg: dependency problems prevent configuration of libgs9:amd64: libgs9:amd64 depends on libpaper1; however: Package libpaper1:amd64 is not configured yet. dpkg: error processing package libgs9:amd64 (--configure): dependency problems - leaving unconfigured dpkg: dependency problems prevent configuration of ghostscript: ghostscript depends on libgs9 (= 9.26~dfsg+0-0ubuntu0.18.10.9); however: Package libgs9:amd64 is not configured yet. dpkg: error processing package ghostscript (--configure): dependency problems - leaving unconfigured Processing triggers for libc-bin (2.28-0ubuntu1) ... Errors were encountered while processing: libpaper1:amd64 libpaper-utils unattended-upgrades libgs9:amd64 ghostscript E: Sub-process /usr/bin/dpkg returned an error code (1)
編輯
回應@Stefan Skoglund 的問題:
~ $ sudo apt-cache policy libpaper1 libpaper1: Installed: 1.1.24+nmu5ubuntu1 Candidate: 1.1.24+nmu5ubuntu1 Version table: *** 1.1.24+nmu5ubuntu1 500 500 http://mirror.hetzner.de/ubuntu/packages cosmic/main amd64 Packages 500 http://de.archive.ubuntu.com/ubuntu cosmic/main amd64 Packages 100 /var/lib/dpkg/status ~ $ sudo dpkg-reconfigure -plow libpaper1 /usr/sbin/dpkg-reconfigure: libpaper1 is broken or not fully installed
編輯 2
我不顧一切,閉上眼睛,十指交叉,試了試:
sudo apt-get --purge remove libpaper1:amd64 libpaper-utils unattended-upgrades libgs9:amd64 ghostscript sudo apt-get clean sudo apt-get update && sudo apt-get upgrade sudo apt autoremove
它神奇地起作用了。
賞金仍然可供可以解釋此處發生的事情以及最佳實踐/故障排除提示的人使用。
這裡發生的是 libpaper1 包的安裝後腳本被破壞,並在安裝過程中出錯退出。這不應該發生,因為它就像您所經歷的那樣破壞了包狀態,這就是為什麼向包維護者報告錯誤是個好主意。有關詳細資訊,請參閱ReportingBugs wiki 頁面。
您的選擇如下:
移除包並等待修復。這就是您的情況可能發生的情況:當您決定清除 libpaper1 軟體包時,它已得到修復,並且新安裝成功。
需要注意的是,無論是否有可用的升級包,都不會在包狀態損壞時下載。因此,您必須刪除該軟體包,然後重新安裝。
修復安裝後腳本。如果您真的、絕對需要該軟體包,並且您不想等到修復,這是一個替代方案。您確實需要知道自己在做什麼(必須具備 shell 程式知識),但修復腳本通常很簡單。
每個軟體包都可以有一個預安裝和一個安裝後腳本,它們駐留在
/var/lib/dpkg/info
目錄中,並命名package[:arch].preinst
為package[:arch].postinst
. 這些分別在安裝之前和之後執行$$ * $$. 在您的情況下,安裝後腳本失敗,這意味著軟體包已安裝(因此文件已被提取),唯一剩下的就是執行安裝後腳本。因此,您需要做的是
libpaper1:amd64.postinst
從根終端執行腳本 ( ),並記錄發生錯誤的行。從這裡修復腳本通常是微不足道的,但請務必了解腳本試圖做什麼,因為失敗的命令可能對包至關重要。請嘗試實際修復腳本(例如,附加|| true
到行尾,但可能不是最好的主意)。如果腳本執行沒有錯誤,則
dpkg --configure -a
命令將配置所有待處理的包,並在此過程中執行 postinstall 腳本,恢復包狀態。
$$ * $$實際過程當然要復雜一些;如果您想知道在安裝/刪除期間究竟發生了什麼,請參閱dpkg(1) 手冊頁中的 、 和 操作
install
的configure
描述。remove