{"id":7478,"date":"2021-06-24T06:09:28","date_gmt":"2021-06-24T06:09:28","guid":{"rendered":"https:\/\/linuxways.net\/?p=7478"},"modified":"2021-06-24T06:09:28","modified_gmt":"2021-06-24T06:09:28","slug":"how-to-solve-e-could-not-get-lock-var-lib-dpkg-lock-error-in-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-solve-e-could-not-get-lock-var-lib-dpkg-lock-error-in-ubuntu\/","title":{"rendered":"How to Solve \u2018E: Could not get lock \/var\/lib\/dpkg\/lock\u2019 Error in Ubuntu"},"content":{"rendered":"<p>If you are a regular Ubuntu\/ Debian user, you might have, at some point in time, come across the error: \u2018<strong>Could not get lock \/var\/lib\/dpkg\/lock<\/strong>\u2019. This happens to be related to the error<strong> \u2018Could not get lock \/var\/lib\/apt\/lists\/lock\u2019<\/strong>. Below is a screenshot displaying such an error.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"988\" height=\"215\" class=\"wp-image-7479\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-634.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-634.png 988w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-634-300x65.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-634-768x167.png 768w\" sizes=\"auto, (max-width: 988px) 100vw, 988px\" \/><\/strong><\/p>\n<p>This is a non-fatal error and is usually not a major cause of concern. It can easily be resolved as we shall later demonstrate. But what causes it in the first place? Let\u2019s find out.<\/p>\n<h2><strong>Causes of the error<\/strong><\/h2>\n<p>The common cause of this error is when a process is using the APT package manager to update\/upgrade\/install software or perform some package management on the system. When this happens, the process locks the dpkg file using a lock file such that another process doesn\u2019t alter the data which is likely to lead to errors and possible corruption of crucial files in the system.<\/p>\n<p>Whenever you encounter this error, there a high chance that there is another simultaneous process running APT. This could be a process running concurrently on another terminal. The error can also occur due to an interrupted update or upgrade process which was prematurely terminated by pressing CTRL + C on the terminal or accidental closure of the terminal window.<\/p>\n<h2><strong>How to resolve the Could not get lock \/var\/lib\/dpkg\/lock error<\/strong><\/h2>\n<p>Here are a few tips that can help remediate the error and help you get back to using the APT package manager.<\/p>\n<h2><strong>Wait for the process to finish<\/strong><\/h2>\n<p>If you have another terminal session where the APT package manager is being used by a command such as updating or upgrading the system or installing an application, just allow the operation to finish successfully. After completion, you can then run the command you want and perform any other operation using APT.<\/p>\n<h2><strong>Terminate processes using the APT package manager<\/strong><\/h2>\n<p>If you interrupted a process using APT such as canceling an upgrade or an update of the package index, first identify the processes using APT using the ps command shown:<\/p>\n<pre><strong>$ ps aux | grep -i apt<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"862\" height=\"215\" class=\"wp-image-7480\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-635.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-635.png 862w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-635-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-635-768x192.png 768w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/p>\n<p>From the output, we can see that APT is used by two processes started by root. The processes bear the PIDs <strong>3994<\/strong> and <strong>3999<\/strong>. Once you have identified the processes using APT, the next course of action is to kill or terminate the processes.<\/p>\n<p>To achieve this, use the kill command as follows.<\/p>\n<pre><strong>$ kill -9 PID<\/strong><\/pre>\n<p>From the output, we will kill the processes bearing the PIDs of <strong>3994<\/strong> and <strong>3999 <\/strong>as follows:<\/p>\n<pre><strong>$ kill -9 3994<\/strong><\/pre>\n<pre><strong>$ kill -9 3999<\/strong><\/pre>\n<p>The <strong>-9 <\/strong> flag triggers a SIGKILL signal which terminates a process immediately without allowing it to exit gracefully.<\/p>\n<p>A much simpler way is to use the <strong>killall<\/strong> command as shown.<\/p>\n<pre><strong>$ killall apt apt-get<\/strong><\/pre>\n<p>Once you have killed the problematic processes, you can now proceed to use the APT package manager in your command.<\/p>\n<h2><strong>Remove the lock files<\/strong><\/h2>\n<p>The other fix you can apply is to remove the lock files. As earlier discussed, the lock files prevent the access of data by two different processes. To get rid of the lock files, run the following commands.<\/p>\n<pre><strong>$ sudo rm \/var\/lib\/dpkg\/lock<\/strong><\/pre>\n<pre><strong>$ sudo rm \/var\/lib\/dpkg\/lock-frontend<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"215\" class=\"wp-image-7481\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-636.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-636.png 794w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-636-300x81.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-636-768x208.png 768w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><\/p>\n<p>And finally, reconfigure the packages.<\/p>\n<pre><strong>$ sudo dpkg --configure -a<\/strong><\/pre>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Any of these solutions will help you navigate around this error and let you use the APT package manager for other operations. Do let us know what worked for you.<\/p>","protected":false},"excerpt":{"rendered":"<p>If you are a regular Ubuntu\/ Debian user, you might have, at some point in time, come across the error: \u2018Could not get lock \/var\/lib\/dpkg\/lock\u2019. This happens to&hellip;<\/p>","protected":false},"author":1,"featured_media":7654,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/7478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=7478"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/7478\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/7654"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=7478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=7478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=7478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}