Linux unable to lock directory

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

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

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

3 Answers 3

Run the following command :

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):

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 
ps -e | grep -e apt -e adept | grep -v grep 

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

Читайте также:  Rescue mode kali linux

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)

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.

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:

Afterwards force package(s) to reconfigure like so:

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 

Источник

Fix “Unable to lock the administration directory (/var/lib/dpkg/)” in Ubuntu

While using the apt-get command or the relatively new APT package management tool in Ubuntu Linux or its derivatives such as Linux Mint (which I actually use as my primary operating system for doing daily work), you might have encountered the error – “unable to lock the administration directory (/var/lib/dpkg/) is another process using it” on the command line.

This error can be so annoying especially for new Linux (Ubuntu) users who may not know exactly the cause of the error.

Below is an example, showing the lock file error in Ubuntu 16.10:

[email protected]:~$ sudo apt install neofetch [sudo] password for tecmint: 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?

The output below is another possible instance of the same error:

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable) E: Unable to lock directory /var/lib/apt/lists/ 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 you solve the above error in case you bump into it in the future? There are several ways of dealing with this error(s), but in this guide, we will go through the two easiest and probably the most effective ways of solving it.

Читайте также:  What are threads in linux

1. Find and Kill all apt-get or apt Processes

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.

Find apt and apt-get Processes

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

2. Delete the lock Files

A lock file simply prevents access to another file(s) or some data on your Linux system, this concept is present in Windows and other operating systems as well.

Once you run an apt-get or apt command, a lock file is created under the any of these directories /var/lib/apt/lists/, /var/lib/dpkg/ and /var/cache/apt/archives/.

This helps to avoid the apt-get or apt process that is already running from being interrupted by either a user or other system processes that would need to work with files being used by apt-get or apt. When the process has finished executing, the lock file is then deleted.

Important: In case a lock is still exiting in the two directories above with no noticeable apt-get or apt process running, this may mean the process was held for one reason or the other, therefore you need to delete the lock files in order to clear the error.

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

Afterwards force package(s) to reconfigure like so:

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

In conclusion, we have walked through two important methods to deal with a common problem faced by Ubuntu (and its derivatives) users, while running apt-get or apt as well as aptitude commands.

Читайте также:  Install ntp on linux

Do you have any other reliable methods to share meant for deal with this common error? Then get in touch with us via the feedback form below.

In addition, you may as well want to learn how to find and kill running processes and read through a simple guide to kill, pkill and killall commands to terminate a process in Linux.

Источник

Fix E: Could not get lock /var/cache/apt/archives/lock [Quick Tip]

The other day a reader asked me that she had troubles with this kind of error:

E: Could not get lock /var/cache/apt/archives/lock – open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/cache/apt/archives/

She was trying to follow one of the tips mentioned in things to do to after installing Ubuntu 14.04 when she encountered this error. Its one of the common occurring update errors in Ubuntu and also one of the least annoying ones.

Reason:

If you are wondering what caused this error in the first place, the reason is quite evident in the error itself. The error says: Could not get lock /var/cache/apt/archives/lock – open (11: Resource temporarily unavailable). And this is what precisely happening.

While you are trying to install some package with apt command, some other package manager is running or an update is going on.

It is possible that you have Software Center open or another terminal is using the apt or apt-get commands.

Solution:

The first and foremost thing is to do nothing. I mean once the other program that is using the resource completes the process, the resources will be available again.

Otherwise, look for other programs that might be using apt. Close that program.

You can also search if there is an instance of apt command running (use ps aux | grep -i apt) and then kill the process.

An easier way to do that would be to use the killall command:

If the above commands don’t fix the issue of E: Could not get lock /var/cache/apt/archives/lock – open (11: Resource temporarily unavailable), try the following commands one by one to fix the issue:

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

The above commands remove the lock files and thus apt and dpkg packag management process are free to be used again. Though not necessary, you may need to reconfigure dpkg with the command below:

I hope this quick tip helps in solving this common update error in Ubuntu. Any questions or suggestions are welcomed. Ciao 🙂

Источник

Оцените статью
Adblock
detector