Ubuntu中Could not get lock /var/lib/dpkg/lock解決方案

在運(yùn)行apt-get update時(shí)出現(xiàn)這個(gè)問(wèn)題
2:參考博客:

在Ubuntu中,有時(shí)候運(yùn)用sudo apt-get install 安裝軟件時(shí),會(huì)出現(xiàn)一下的情況

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

3:?jiǎn)栴}原因:主要是因?yàn)閍pt還在運(yùn)行。

4:解決方案:殺死所有的apt進(jìn)程。

1:查找所有apt相關(guān)的進(jìn)程,并用命令殺死。

hlp@hlp-Lenovo-G405:~$ ps afx|grep apt
 3284 pts/0    S+     0:00          \_ grep --color=auto apt
 2869 ?        Ss     0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
 2873 ?        S      0:00  \_ /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install

hlp@hlp-Lenovo-G405:~$ sudo kill -9 2873
hlp@hlp-Lenovo-G405:~$ sudo kill -9 2869

2:刪除鎖定文件

鎖定的文件會(huì)阻止 Linux 系統(tǒng)中某些文件或者數(shù)據(jù)的訪問(wèn),這個(gè)概念也存在于 Windows 或者其他的操作系統(tǒng)中。

一旦你運(yùn)行了 apt-get 或者 apt 命令,鎖定文件將會(huì)創(chuàng)建于 /var/lib/apt/lists/、/var/lib/dpkg/、/var/cache/apt/archives/ 中。

這有助于運(yùn)行中的 apt-get 或者 apt 進(jìn)程能夠避免被其它需要使用相同文件的用戶或者系統(tǒng)進(jìn)程所打斷。當(dāng)該進(jìn)程執(zhí)行完畢后,鎖定文件將會(huì)刪除。

所以:

1:移除對(duì)應(yīng)目錄下的鎖文件:

2:強(qiáng)制重新配置軟件包:

3:更新軟件包源文件:

hlp@hlp-Lenovo-G405:~$ sudo rm /var/lib/dpkg/lock

hlp@hlp-Lenovo-G405:~$ sudo dpkg --configure -a

hlp@hlp-Lenovo-G405:~$ sudo apt update
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容