[Hardy] How to open lock in aptitude

Asked by Shirish Agarwal on 2008-02-12

Hi all,
   Lots of times I get stuff like this below :-

shirish@Mugglewille:~$ sudo aptitude safe-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following packages will be upgraded:
  capplets-data deskbar-applet espeak espeak-data file-roller foomatic-db gnome-control-center gnome-orca
  libespeak1 libgnome-window-settings1 libgnomeui-0 libgnomeui-common libusplash0 openprinting-ppds splix
  usplash vino
17 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 8273kB of archives. After unpacking 1786kB will be used.
Do you want to continue? [Y/n/?] Y
E: Could not get lock /var/lib/apt/lists/lock - open (11 Resource temporarily unavailable)
E: Couldn't lock list directory..are you root?

Now as I can see, I'm root but still this issue, any ideas wjy? How to work through it or about it?

Aptitude version :- 0.4.9-2ubuntu4

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu aptitude Edit question
Assignee:
No assignee Edit question
Last query:
2008-03-05
Last reply:
2011-10-01

Try first:

"sudo -i" (add pasword to have root terminal) and then "aptitude ...."

Adrian Petrescu (apetresc) said : #2

Make sure you don't have any other instance of Synaptic or Adept or Update-Manager, etc, running at the same time.
Only ONE process can use apt at a time. This is usually the cause of these errors. Close all instances of package manager programs and try again.

Shirish Agarwal (shirishag75) said : #3

Hi all,
 I just browsed through & saw couple of ways in which things can be resolved.

First of all this is a bug which I guess everybody has just forgotten.

https://bugs.edge.launchpad.net/ubuntu/+source/adept/+bug/48627/

From this it seems it just requires a

dpkg --configure -a command.

There is/was also another way described in the mails.

https://lists.ubuntu.com/archives/kubuntu-users/2007-August/019329.html

although how relevant or not the answer is as it was given in Feisty is upto you guys.

I'm going to keep the question till the next time I hit the lock issue & see if the above command

dpkg --configure -a

If that solves the issue then will put the status to Problem Solved.

Shirish Agarwal (shirishag75) said : #4

Hi all,
 Tried various things & it works, sort off but without knowing what is the correct way.

First tried the dpkg --configure -a command. It gave

shirish@Mugglewille:~$ sudo dpkg --configure -a
dpkg: status database area is locked by another process

Then it was the time to do the second one but its just not me to do things the right way.

Hence this is what I did.

I made a file & called it unlock.sh

The contents of which are :-

rm /var/cache/apt/archives/lock
rm /var/lib/aptitude/lock
rm /var/lib/dpkg/lock
rm /var/lib/apt/lists/lock

Then I chmodded that file 777 to make it executable & everything.

Running that file gave me the following output :-

shirish@Mugglewille:~$ sudo ./unlock.sh
rm: cannot remove `/var/cache/apt/archives/lock': No such file or directory
rm: cannot remove `/var/lib/aptitude/lock': No such file or directory
rm: cannot remove `/var/lib/dpkg/lock': No such file or directory

Then I just installed a random application & got the following output.

shirish@Mugglewille:~$ sudo aptitude install rawstudio
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Could not get lock /var/lock/aptitude - open (11 Resource temporarily unavailable)
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following NEW packages will be installed:
  rawstudio
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 238kB of archives. After unpacking 614kB will be used.
Get:1 http://archive.ubuntu.com hardy/universe rawstudio 0.7-1 [238kB]
Fetched 238kB in 7s (32.2kB/s)
Selecting previously deselected package rawstudio.
(Reading database ... 359492 files and directories currently installed.)
Unpacking rawstudio (from .../rawstudio_0.7-1_i386.deb) ...
Setting up rawstudio (0.7-1) ...

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Could not get lock /var/lock/aptitude - open (11 Resource temporarily unavailable)
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done

The could not get lock statement worries me, hence did a dpkg--configure -a after that.

Anybody has any better ideas?

It just happened to me and I figured it out. dpkg uses this file to obtain a lock in Ubuntu:
/var/lib/dpkg/lock

So you need to (as root)
#rm /var/lib/dpkg/lock

Also, aptitude uses this file to obtain a lock:
/var/lock/aptitude INSTEAD OF "/var/lib/aptitude/lock"

So you need to (as root):
#rm /var/lock/aptitude

John McCabe-Dansted (gmatht) said : #6

> Then I chmodded that file 777 to make it executable & everything.

I would recommend against using 777. That makes the file world writable, and having world writable executables is quite bad for security. I would recommend
  chmod 755 myshfile.sh
instead.

Arif Arham (arhamlinux) said : #7

Reinstall apt!
Go to http://packages.ubuntu.com/hardy/apt (if you use Hardy), and download one package: apt. Then, install it.
Try 'sudo apt-get update', it should work now.

Onkar Raut (raut-onkar) said : #8

THIS WORKED PERFECTLY FOR ME......

ps -e | grep apt (might show you a number which is essentially a job number. My system was locked due to apt-get and showed me apt-get as job number 1594)

sudo kill 1594 (modify number to your current run)

This works perfect without having to delete the lock and causing unnecessary changes to your system

Tim S (timss) said : #9

Thanks a bunch Onkar Raut!
I was anxious to delete files as root, which should not at all be needed, glad I read all the comments!
Debian 6.
- Tim

Can you help with this problem?

Provide an answer of your own, or ask Shirish Agarwal for more information if necessary.

To post a message you must log in.