Step-by-Step Guide
Wait for the Current Process to Complete
Sometimes, the best approach is to wait a few minutes for the current process to complete. If the issue persists, proceed with the following steps.
Identify the Process Holding the Lock
Identify the process holding the lock and see if it is still active:
sudo lsof /var/lib/dpkg/lock
This will show you the process that is currently using the lock. Alternatively, you can use the ps command:
ps aux | grep dpkg
Terminate the Process (if necessary)
If you determine that the process is not performing any critical operations or it is stuck, you can terminate it. Replace PID with the process ID you found in the previous step:
sudo kill -9 PID
Remove the Lock Files
After terminating the process, you can safely remove the lock files:
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/cache/apt/archives/lock
Reconfigure dpkg
Sometimes, dpkg can be left in an inconsistent state. Running the following command can fix this:
sudo dpkg --configure -a
Update and Install Packages Again
Now you should be able to update your package list and install packages without issues:
sudo apt-get update
sudo apt-get install php7.4-mysqli