7

I recently installed a fresh version of Ubuntu LTS 12.04. I had been using LTS 10.4 and saved my package.list and was planning on using

$> sudo dpkg --set-selections < package.list && apt-get dselect-upgrade

to install the same packages in the new version

However, the computer fails to run with the error

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)  
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

The simple answers to this would be am I root or a member of sudo?

  $> whoami

  surfer

   $> groups

surfer adm cdrom sudo dip plugdev lpadmin sambashare

So much for the easy answer.

Per the similar post Unable to lock the administration directory (/var/lib/dpkg/) is another process using it? The recommended solution is

$> sudo fuser -cuk /var/lib/dpkg/lock; sudo rm -f /var/lib/dpkg/lock

Upon executing that command, my screen goes blank, the keyboard becomes unresponsive, and my only option is to press the power button and reboot... (I would have thought this was a malicious suggestion, but many others seemed to have liked it.)

I've tried listing any programs that may be using /var/lib/dpkg/lock

$> sudo lsof 

lsof: WARNING: can't stat() fuse.gvfs-fuse-daemon file system /home/surfer/.gvfs
      Output information may be incomplete.

Note, there are no programs listed.

Similarly, no luck with

$> ps -e | grep -e apt -e adept | grep -v grep

Nothing listed.

BTW, I can run apt-get from the command line.

$> sudo apt-get update

runs as expected and updates my package lists...

@izx: After attempting your suggestion, I could not run

$> sudo dpkg --set-selections < package.list && apt-get dselect-upgrade

It failed with the same error. I tried this

a) immediately following the rm command in the F1 terminal
b) executing the rm command and returning to X with Ctrl+Alt+F7
c) executing the rm command and rebooting

Of interest only option c) yielded a different (but similar error message) which was

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

Although I cannot kill the processes using /var/lib/dpkg/lock with fuser, I did get the following output for processes that are linked to it.

$> fuser -cv /var/lib/dpkg/lock  
                     USER        PID ACCESS COMMAND  
/var/lib/dpkg/lock:  root     kernel mount (root)/var  
                     surfer     1641 ....m (surfer)gnome-settings-  
                     surfer     1656 ....m (surfer)compiz  
                     surfer     1679 ....m (surfer)nm-applet  
                     surfer     1688 ....m (surfer)nautilus  
                     surfer     1731 ....m (surfer)gtk-window-deco  
                     surfer     1733 ....m (surfer)unity-panel-ser  
                     surfer     1831 ....m (surfer)gnome-terminal  
                     surfer     1899 f.... (surfer)unity-applicati  
                     surfer     2029 F...m (surfer)update-notifier   

So I tried killing each process from the F1 terminal, and removed the lock file. No problem. The result was

$> fuser -cv /var/lib/dpkg/lock  
                     USER        PID ACCESS COMMAND  
/var/lib/dpkg/lock:  root     kernel mount (root)/var  

$> ls /var/lib/dpkg/lock  
ls: cannot access /var/lib/dpkg/lock: No such file or directory

file and links seem to be gone, but upon executing the dpkg command, I get the same error...and the lock file is back.

I'm really rather puzzled, and would welcome any help.

1
  • 1
    If you think this below solution solved your problem , do Consider marking it as answer by Ticking the RIGHT tick mark Left to it. Thank You.
    – atenz
    Jul 14, 2012 at 5:32

5 Answers 5

10

Your very First step should have been

sudo dpkg --set-selections < package.list && sudo apt-get dselect-upgrade

The following error

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)  

would have never occurred , Even second time you used the same code, and got same error.

Try the right command by adding sudo as per above , and post your findings.

NOTE : The use of && enables you to execute multiple commands on same line , in the usual sense && only executes the second command if the first command returns a value reporting success . Therefore ,sudo here needs to be specified in second command .

1
  • Thank you tijybba and Eliah. That was the missing element. Works fine now. Changed to Solved.
    – Jim Parker
    Jul 14, 2012 at 2:15
3
sudo dpkg --configure -a

Then retry.

This problem can also arise if there are other installations running.

2
  • As explained in an earlier answer, this problem is caused by one of the apt-get commands that needed to be run as root, not being run as root. Configuring all half-installed packages (sudo dpkg --configure -a) does not address that. Jul 14, 2012 at 15:28
  • Unable to access dpkg status area: No such file or diretory Jul 24, 2016 at 21:03
1

Try with

sudo apt-get update 

If u still get lock error try this command It will give the process detail

ps -e | grep -e apt -e adept | grep -v grep

Then kill the process using process ID then execute the update command

And also u can delete this file your problem will solve

rm /var/lib/dpkg/lock 

sudo dpkg --set-selections < package.list && sudo apt-get dselect-upgrade
0

I had the same error, this worked for me:

This error indicates that you (or some program/script) changed the permissions of the file /var/lib/dpkg/status. Please change them back via: "sudo chmod 644 /var/lib/dpkg/status" in order to fix the issue.

I ended up opening terminal:

sudo nautilus

navigating to the folders/files, and changing permissions to

ME - FOLDER:FULL ACCESS / FILES: READ WRITE

ROOT - FOLDER: FULL ACCESS / FILES: READ ONLY

The problem came when my permissions got screwed when trying to fix a kernel issue I had with an Nvidia driver... but that's another story..

I hope this helps...

0

In rare times, you can get this problem without other dpkg process locks by user with sudo privilege.

I encountered this problem for unknown reasons that I got this folder lost.

I tried all the other solutions suggested here, but none worked. My simple way was to copy a /var/lib/dpkg folder from another server with the same version Ubuntu.

Hope it helps if someone else had the same thing happen to them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .