A Write Lock on a Database Allows Other Users to Read the Data, but They Cannot Update Any Data.ã¢â‚¬â€¹
Recently I was trying to install an application using the apt command on Ubuntu when I encountered the following mistake:
E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
E: Unable to lock the assistants directory (/var/lib/dpkg/), is another process using it?
In fact, there is a similar mistake you lot may see:
East: Could not become lock /var/lib/apt/lists/lock – open (xi: Resource temporarily unavailable)
Eastward: Unable to lock directory /var/lib/apt/lists/
E: Could not become lock /var/lib/dpkg/lock – open up (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using information technology?
In some cases, you might run into information technology while using the Software Center:

These errors are very similar to another common Ubuntu error, Unable to lock directory /var/cache/apt/archives/, and the interesting thing is that the fixes are similar too.
Fixing "Unable to lock the administration directory (/var/lib/dpkg/)" fault
You see this error because another program is trying to update Ubuntu. When a command or awarding is updating the organisation or installing a new software, information technology locks the dpkg file (Debian package manager).
This locking is done so that two processes don't change the content at the same time as it may atomic number 82 to unwarranted situation and a possible broken organisation.
Let'south see what steps tin can you take to ready this issue of 'unable to lock assistants directory'.
Method 0:
The first matter you lot should exercise is to cheque if another program could be running system update or installing a program.
If you are using control line, bank check if an application like Software Middle, Software Updater, Synaptic package manager, Gdebi is running whatever update/installation. If that's the case, please look for the program to terminate the running process.
If there is no such application running, please check all the open up terminal windows and come across if you are running an update or installing a program. If yes, look for it to terminate.
If none of the to a higher place is happening, cheque which other process is running the apt control (package manager for treatment software). Utilize this command:
ps aux | grep -i apt
For me, it showed this output:
[email protected]:~$ ps aux | grep -i apt root 1464 0.0 0.0 4624 772 ? Ss nineteen:08 0:00 /bin/sh /usr/lib/apt/apt.systemd.daily update root 1484 0.0 0.0 4624 1676 ? S 19:08 0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held update _apt 2836 0.8 0.1 96912 9432 ? S nineteen:09 0:03 /usr/lib/apt/methods/http abhishek 6172 0.0 0.0 21532 1152 pts/1 S+ 19:16 0:00 grep --colour=auto -i apt

If yous see that apt is beingness used by a programme like apt.systemd.daily update , yous are in luck, my dear reader.
This is a daemon that runs in the background and check for organisation updates automatically when you start your system.
In Ubuntu 18.04 and higher versions, it may even try to download and install the important security updates on its own. At least this is what I run into in the default settings in Software & Updates tool on the Ubuntu desktop.

If yous are on Ubuntu server, you may check whether y'all take unattended upgrades enabled by checking the content of the file /etc/apt/apt.conf.d/20auto-upgrades .
Then if you see apt.systemd.daily is using the apt process, all y'all take to practice is to look for a few minutes. When the automated update finishes, you should be able to install your software as usual.
As a permanent solution, y'all may disable the check for automatic update and unattended upgrades birthday withal I won't advise that for security reasons.
Now, that was the unproblematic scenario and it could be handled easily. But that might not always exist the case. If some other program is using apt, y'all need to handle it differently.
Method 1:
Employ the Linux command line to notice and kill the running process. To do that, utilise the control beneath:
ps aux | grep -i apt
This will evidence you the id of the process running apt or apt-get. In the case beneath, the procedure id is 7343. You can ignore the concluding line containing 'grep –colour=automobile'.

Yous can use the process id to terminate it by sending the SIGTERM signal. Replace the <process_id> with the number you got in the output of previous command.
sudo impale <process_id>
Bank check if the process was killed by running the 'ps aux | grep -i apt' control. If it is all the same running, force kill it with SIGKILL bespeak:
sudo kill -9 <process_id>
Another, easier way would be to utilise the killall command. This volition kill all the instances of a running programme:
sudo killall apt apt-go
Method two
The above method would fix the trouble for you in nearly cases. But my case was a bit different. I was updating my organization and accidentally closed the terminal. For that reason, there were no processes running apt, merely it still showed me the error.
I would propose trying the above two methods or but restarting your arrangement first. If none of that works, and so only you become for this option of removing the lock files.
In this case, the root cause is the lock file. As mentioned earlier, the lock files are used to foreclose two or more than processes from using the aforementioned data. When apt or apt-get commands are run, they create lock files in a few places. If the previous apt command was not terminated properly, the lock files are non deleted and hence they foreclose any new instances of apt-get or apt commands.
To gear up the problem, all you need to do is to remove the lock files. Only before yous do that, it would be a good idea to stop whatever process that is using the lock files.
Use the lsof control to become the process ID of the process belongings the lock files. Cheque the error and see what lock files it is complaining about and get the id of the processes belongings these lock files.
Run these commands one by one.
sudo lsof /var/lib/dpkg/lock sudo lsof /var/lib/apt/lists/lock sudo lsof /var/enshroud/apt/athenaeum/lock
It's possible that the commands don't return anything, or return just one number. If they exercise render at least i number, use the number(southward) and kill the processes like this (replace the <process_id> with the numbers you got from the above commands):
sudo kill -nine <process_id>
You can at present safely remove the lock files using the commands below:
sudo rm /var/lib/apt/lists/lock sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock
After that, reconfigure the packages:
sudo dpkg --configure -a
Now if you run the sudo apt update command, everything should be fine.
Troubleshooting one: "Unable to acquire the dpkg frontend lock"
If you lot see an fault like this:
[e-mail protected]:~$ sudo apt install grub-customizer E: Could non get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
You should find out which process is holding the lock-frontend using the lsof command as discussed in previous sections:
sudo lsof /var/lib/dpkg/lock-frontend
This is what it showed for me:
[email protected]:~$ sudo lsof /var/lib/dpkg/lock-frontend lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs Output information may be incomplete. COMMAND PID USER FD Type DEVICE SIZE/OFF NODE NAME unattende 2823 root 5uW REG 8,2 0 145221 /var/lib/dpkg/lock-frontend
If you run into 'unattende' COMMAND column, this means unattended security upgrades are running. You should wait for the process to cease. Basically, this is what I discussed in method 0 only you probably skipped that.
If the COMMAND is something else, you may kill the process and so remove the lock file. You tin run across the procedure id under the PID column. Use this PID to impale the procedure. After that, remove the lock file and run the update control to see if it's been stock-still.
sudo kill -ix PID sudo rm /var/lib/dpkg/lock-frontend sudo apt update
What'southward that lsof: warning can't stat() fuse.gvfsd-fuse file system?
Note: If you see "lsof: warning can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may exist incomplete" lines after running the earlier mentioned lsof control, don't panic.
That's not an error. It'due south just that lsof tries to wait into mounted file systems likewise and the alert is nearly those mounted systems.
The files are locked by the processes on your main filesystem so if it shows some alarm and no output, this just means that at that place is no process using those lock files.
Troubleshooting 2: "dpkg: mistake: dpkg frontend is locked by another process"
If y'all come across the error "dpkg frontend is locked by another process" while running the steps in method two, y'all need to 1 boosted footstep.
First, discover out the id of the procedure that is holding the lock file.
sudo lsof /var/lib/dpkg/lock-frontend
The to a higher place control will give y'all the details of the processes using the lock files. Utilise the procedure ID to impale this program:
sudo kill -9 PID
Now y'all can remove the lock and reconfigure dpkg:
sudo rm /var/lib/dpkg/lock-frontend sudo dpkg --configure -a
Did information technology work for you? Which method stock-still it for you?

I hope this modest tip helped you fix the "Could not get lock /var/lib/dpkg/lock" fault. If yes, delight let me know in comments which method worked for you.
If y'all are yet facing issue, let me know. I'll try to help you out.
Any other suggestions are also welcome in the comments.
Source: https://itsfoss.com/could-not-get-lock-error/
Posting Komentar untuk "A Write Lock on a Database Allows Other Users to Read the Data, but They Cannot Update Any Data.ã¢â‚¬â€¹"