修復刪除/var/lib/dpkg目錄後,沒法使用apt-get命令問題

Unfortunately I've deleted dpkg directory while removing the lock. By mistake I typedcode

root@sam:~$ rm -r /var/lib/dpkg

Now when I am trying to install/uninstall packages it shows me following error.rem

E: Could not open lock file /var/lib/dpkg/lock - open (2: No such file or directory)

What should I do now?get

解決:it

 

You removed 5 directories, the status file, etc. So, lets try to fix the stuff. First, create the directory:date

sudo mkdir -p /var/lib/dpkg/{alternatives,info,parts,triggers,updates}

Recover some backups:file

sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status

Now, let's see if your dpkg is working (start praying):error

apt-get download dpkg
sudo dpkg -i dpkg*.deb

If everything is "ok" then repair your base files too:di

apt-get download base-files
sudo dpkg -i base-files*.deb

Now try to update your package list, etc.:vi

dpkg --audit
sudo apt-get update
sudo apt-get check

Now, let's take a deep breath. Phew. Do ls -l /var/lib/dpkg and compare with the above list. If some -old file is not present don't worry it will be there tomorrow.while

相關文章
相關標籤/搜索