Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

An older version of a cookbook installed a package that I no longer want on my systems. My understanding is that chef doesn't have a straightforward way to explicitly remove a package, so I resorted to the blunt hammer of execute:

execute "Remove nasty perl gearman-server" do
    command "apt-get -y remove gearman-server"
    ignore_failure true

But this fails, I'm guessing because chef itself has the lock on dpkg?

STDERR: 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?

How can I programmatically ensure that this package is no longer on my machines? If it's not clear, I'm totally happy with an ubuntu-only solution.

share|improve this question
That error indicates some other package tool was already running. Were doing something in another window/terminal? I don't know chef, but I find it difficult to believe that it create that lock. – Zoredache Jan 3 '13 at 22:10
Agreed. The lock must have been taken by another dpkg or apt process, possibly another chef-client also. – Tim Potter Jan 3 '13 at 22:35
up vote 5 down vote accepted

The Chef package resource allows removal or purging of packages in a distro independent manner:

package "gearman-server" do
  action :remove

This code will remove the package if it is installed, or do nothing if the package is not.

share|improve this answer

Your Answer


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.