Unable to lock the administration directory (/var/lib/dpkg/) error when trying to install unrar from the terminal in Ubuntu

4

1

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?

hasee

Posted 2016-08-01T05:31:45.550

Reputation: 51

1please anyone help by solving my error. – hasee – 2016-08-01T05:32:25.240

As the error asks, are you root or running the command with sudo? – Julie Pelletier – 2016-08-01T05:33:17.160

sudo apt-get install whatever should do the trick. Missing sudo as pointed out by @JuliePelletier – pun – 2016-08-01T05:34:36.447

I am trying to install $ sudo apt-get install unrar.but still it showing the same error – hasee – 2016-08-01T05:36:32.367

Is this happening on a fresh install? – Julie Pelletier – 2016-08-01T05:39:42.083

rm -r /var/lib/dpkg/* long back i run this command in my terminal.after running this command i am getting bellow error every time when i am trying to install any software sudo apt-get install unrar [sudo] password for user: 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? – hasee – 2016-08-01T05:42:40.537

1Do you get any result when running sudo ls -l /var/lib/dpkg? – Julie Pelletier – 2016-08-01T05:45:40.083

ls: cannot access '/var/lib/dpkg': No such file or directory this is the result i am getting after entering the sudo ls -l /var/lib/dpkg – hasee – 2016-08-01T05:48:11.727

1Then try sudo mkdir /var/lib/dpkg but I suspect the problem could be much worse. – Julie Pelletier – 2016-08-01T05:53:45.400

user@user-Vostro-3800:~$ sudo mkdir /var/lib/dpkg user@user-Vostro-3800:~$ sudo -i root@user-Vostro-3800:~# sudo mkdir /var/lib/dpkg mkdir: cannot create directory ‘/var/lib/dpkg’: File exists – hasee – 2016-08-01T05:57:21.433

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 – 2016-08-01T06:26:47.917

@karel, looks like you have some insight that I don't. You think all of the details in the comments are basically noise (not really relevant to a solution), and the 2nd and 3rd bullets in your answer pretty much have to cover the problem? – fixer1234 – 2016-08-01T07:13:25.107

@hasee, I had shut down for the night and now can't tell from the comment timings whether karel's super-cure worked (if it did, you can accept the answer by clicking the checkmark; that will let people know the problem is solved and identify that as a proven solution for others with a similar problem). If it didn't solve it, my understanding is that things can get hosed in a way apt can't fix. I think that's where Julie Pelletier was going with the comment about a fresh install. Sometimes the most reliable, and fastest, solution is to restore from a backup or do a clean install. (cont'd) – fixer1234 – 2016-08-01T16:56:25.543

See if your system has the Aptik Migration Utility. That will create a list of all the changes you've made to the stock installation and provide a mechanism to do an automated recreation of the current configuration. – fixer1234 – 2016-08-01T16:56:33.513

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. – Julie Pelletier – 2016-08-01T16:56:51.717

Related thread on askUbuntu exchange - Permission denied, are you root?

– RBT – 2018-05-10T00:06:18.800

Answers

7

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

GAD3R

Posted 2016-08-01T05:31:45.550

Reputation: 2 677

0

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

karel

Posted 2016-08-01T05:31:45.550

Reputation: 11 374

$ 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 – 2016-08-01T06:23:43.107

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 – 2016-08-01T07:33:24.593

0

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
or
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
or
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
or
sudo apt-get update

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

Toir427

Posted 2016-08-01T05:31:45.550

Reputation: 11