When you see this error, it means that another application (or process) is currently using apt
, and thus it cannot be used by your desired process (since only one process may use it at any one time).
If you are using Ubuntu desktop, it is most likely that it is checking for updates or installing updates in the background. You may be able to investigate who or what is using it by using the "System Monitor" application, or htop
.
If you are certain that nothing is running, you can try to kill any processes, with killall
command. For example: sudo killall apt-get
, sudo killall apt
or sudo killall dpkg
. Also try a system reboot (this works for me every time I see this error).
If all this fails, you can just remove the lock
file, since a process creates the file when using it, and deletes it automatically after, however if the process was interupted (aborted, crashed etc.), it would still be there. Run sudo rm -rf /var/lib/dpkg/lock
to remove this.