包管理 - sudo apt get update返回错误

分享于 

4分钟阅读

ubuntu

  繁體

问题:

sudo apt-get update返回一个错误:


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?




$ sudo lsof /var/lib/dpkg/lock


lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs


 Output information may be incomplete.


COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME


aptitude 2166 root 3uW REG 252,0 0 49021509 /var/lib/dpkg/lock



$ sudo lsof /var/lib/apt/lists/lock


lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs


 Output information may be incomplete.



$ sudo lsof /var/cache/apt/archives/lock


lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs


 Output information may be incomplete.



$ sudo dpkg --configure -a


dpkg: error: dpkg status database is locked by another process



  • 重启后,我得到以下结果:

    
    $ sudo lsof /var/lib/dpkg/lock
    
    
    lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
    
    
     Output information may be incomplete.
    
    
    
    $ sudo lsof /var/lib/apt/lists/lock
    
    
    lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
    
    
     Output information may be incomplete.
    
    
    
    $ sudo lsof /var/cache/apt/archives/lock
    
    
    lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
    
    
     Output information may be incomplete.
    
    
    lsof: status error on /var/cache/apt/archives/lock: No such file or directory
    
    
    lsof 4.86
    
    
     latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
    
    
     latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
    
    
     latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
    
    
     usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
    
    
     [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
    
    
    [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
    
    
    Use the ``-h'' option to get more help information.
    
    
    
    

    我也尝试了

    
    sudo dpkg --configure -a
    
    
    
    
    
    sudo apt-get update
    
    
    
    

  • 答案1:

    我将按顺序回答你的问题,因为我可以。

    sudo lsof /var/lib/dpkg/lock

    
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    
    
    aptitude 2166 root 3uW REG 252,0 0 49021509 /var/lib/dpkg/lock
    
    
    
    

    该如何解决?

    你可以运行sudo rm /var/lib/dpkg/lock来中断锁,可以通过运行 ps -aux | grep dpkg 或者 ps -aux | grep apt

    通过运行sudo kill <PID>来执行此操作,其中<PID>lsof条目中的数字,在本例中为2166

    如果强制杀死apt,并破坏锁,最好运行dpkg --configure -a,让DPKG修复可能损坏的内容。


  • 如何找到使用它的进程?
  • 
    ps -fea | grep apt
    
    
    
    

    然后,一旦确定了进程,你需要杀死它。

     
    kill -9 nnnn
    
    
    
    

    其中nnnn是进程号。


  • 重新启动系统以确保apt没有运行
  • 删除锁定文件(sudo rm /var/lib/dpkg/lock )


  • MAN  PAC  PACK  GET  APT  SUDO