因安裝包依賴問題導致無法安裝的解決辦法!


在 Ubuntu 中安裝軟件的時候經常碰到 E: Unable to correct problems, you have held broken packages. 的錯誤,顧名思義是因為某些軟件包沖突導致,幸運的話 sudo apt-get update && sudo apt-get upgrade 可以解決,但這種情況屬於可遇不可求,更多的適合這么做不濟於事。這樣一來如何徹底解決就成了一個問題,經過多次摸索之后,將可行的解決方法記錄如下:

以安裝 libxml2-dev 時錯誤為例,安裝時提示如下錯誤:
$ sudo apt-get install libxml2-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
 libxml2-dev : Depends: libxml2 (= 2.7.8.dfsg-5.1ubuntu4) but 2.7.8.dfsg-5.1ubuntu4.6 is to be installed

解決方法如下:

$sudo apt-get install aptitude
$aptitude why-not libxml2
p   shared-mime-info:i386 Provides shared-mime-info                  
p   shared-mime-info:i386 Depends  libxml2:i386 (>= 2.7.4)           
p   libxml2:i386          Breaks   libxml2 (!= 2.7.8.dfsg-5.1ubuntu4)

$dpkg -l | grep libxml2
找到已經安裝的對應的 libxml2 包
$sudo dpkg --purge --force-all libxml2

刪除 libxml2,並刪除其他所有依賴包,--force-all 參數很重要

$sudo apt-get -f install

強制安裝欠缺的包

$sudo apt-get install libxml2-dev


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM