I am getting this error when trying to install unrar unarchiver for .rar files from the terminal in Ubuntu.

E: Could not open lock file /var/lib/dpkg/lock - open (2: No such file or directory)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
  • 1
    please anyone help by solving my error.
    – hasee
    Aug 1, 2016 at 5:32
  • 1
    Do you get any result when running sudo ls -l /var/lib/dpkg? Aug 1, 2016 at 5:45
  • 1
    Then try sudo mkdir /var/lib/dpkg but I suspect the problem could be much worse. Aug 1, 2016 at 5:53
  • 1
    @hasee, obviously, you're getting the error messages because something is messed up and not working normally. Your question doesn't contain any history of how you got to this point or diagnostic details. Some of that is in comments, but it's incomplete and hard to follow. People will be better able to help if you edit the question and add the detail from the comments (and do it in an organized way).
    – fixer1234
    Aug 1, 2016 at 6:26
  • 1
    @hasee: Please double-check what you tried because sudo ls -l /var/lib/dpkg can not tell you that there is no such file or directory while sudo mkdir /var/lib/dpkg would tell you that it exists. Aug 1, 2016 at 16:56

3 Answers 3


Run the following command :

sudo rm /var/lib/dpkg/lock

Create missing folders (use the command ls -l /var/lib/dpkg/ first to display the existing folders, if somes floders exist do not re-create it agin):

sudo mkdir -p /var/lib/dpkg/{alternatives,info,parts,triggers,updates,methods,available,diversions}

Move dpkg.status.0 and repair the base file:

sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
sudo apt-get download dpkg
sudo dpkg -i dpkg*.deb
sudo apt-get download base-files
sudo dpkg -i base-files*.deb
sudo apt update && sudo apt upgrade

Check and repair broken dependencies:

sudo apt-get check
sudo apt -f install
  • The error message is asking if you are root in order to be permitted to run a command to install software from the terminal. Use sudo before a command to run the command with root privileges, like this:

    sudo apt install example-package  

    This example command installs a package named example-package.

  • If you still get a lock error, close the Ubuntu Software Center (Ubuntu 14.04) or Software application (Ubuntu 16.04) and the terminal to unlock /var/lib/dpkg/, reopen the terminal and try the command again.

  • If you still get a lock error, run this command to show details about the locking process.

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

    Then open the System Monitor application and kill the process that has the same process ID as the results of the previous command.

For the error mentioned in the comment:

Errors were encountered while processing: /var/cache/apt/archives/libgtk-3-bin_3.18.9-1ubuntu3.1_amd64.deb   
E: Sub-process /usr/bin/dpkg returned an error code (1)  

Try fixing it by running these commands:

sudo apt-get clean  
sudo apt update  
sudo apt upgrade  
sudo dpkg --configure -a  
sudo apt-get -f install  

Then try running the command that resulted in the error message again.

  • $ sudo apt-get install unrar [sudo] password for user: 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? this is the error now i am getting
    – hasee
    Aug 1, 2016 at 6:23
  • sudo apt-get dist-upgrade I tried above command i got the error as shown bellow Errors were encountered while processing: /var/cache/apt/archives/libgtk-3-bin_3.18.9-1ubuntu3.1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
    – hasee
    Aug 1, 2016 at 7:33

Run the command below to generate a list of all processes whose name comprises of the word apt, you will get a list inclusive of all apt or apt-get processes by using ps and grep commands together with a pipeline.

ps -A | grep apt

For each apt-get or apt process that you can see in the output of the command above, kill each process using the command below.

The process ID (PID) is found in the first column from the screenshot above.

sudo kill -9 processnumber
sudo kill -SIGKILL processnumber

For instance, in the command below where 9 is the signal number for the SIGKILL signal, will kill the first apt process:

sudo kill -9 13431
sudo kill -SIGKILL 13431

First execute the command below to remove the lock file in the /var/lib/dpkg/ directory:

sudo rm /var/lib/dpkg/lock

Afterwards force package(s) to reconfigure like so:

sudo dpkg --configure -a

Alternatively, delete the lock files in the /var/lib/apt/lists/ and cache directory as below:

sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock

Next, update your packages sources list as follows:

sudo apt update
sudo apt-get update

Full info https://www.tecmint.com/fix-unable-to-lock-the-administration-directory-var-lib-dpkg-lock/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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