Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 Fixing "Could not get lock /var/lib/dpkg/lock" 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.

share|improve this question
    
Thanks for giving a lot of information! :-) –  hexafraction Jul 13 '12 at 14:20
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. –  tijybba Jul 14 '12 at 5:32
add comment

4 Answers

up vote 5 down vote accepted

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 .

share|improve this answer
    
Thank you tijybba and Eliah. That was the missing element. Works fine now. Changed to Solved. –  Jim Parker Jul 14 '12 at 2:15
add comment
sudo dpkg --configure -a

Then retry.

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

share|improve this answer
    
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. –  Eliah Kagan Jul 14 '12 at 15:28
add comment

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...

share|improve this answer
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.