When installing or updating packages on Linux distributions, a pesky common error “Unable to lock the administration directory….. locks /var/lib/dpkg” appears frequently. This error has been discussed on various help portals and forums. Yet, many users run into this problem again and again, despite applying for these potential methods as following:
- Detecting the process that holds a lock to the file and killing the process.
- Deleting the locked file to kick off the installation again.
Though these solutions work fine, they may lead to system failure or cause some unwanted problems. In the end, you should find out the “the whys and wherefores” as there may be several reasons, among which the following can be one of the reasons.
“It generally happens when the system uses a particular file throughout the time of pre-programmed periodic OS update, security update, or package update triggered by apt-daily.service.” So in this guide, you will get to know what is systemd daily and how it works in Linux.
What is Apt Systemd Daily?
In Linux distributions, the system is programmed in such a way so it can update the packages itself without an external command. So this task is executed by apt-daily.service, which triggers the system to start apt tasks and scan the packages. This results in the system using some resources periodically and locking some files.
What Does Apt-Daily.Service Do?
- It performs automatic installation of services/ packages
- Look for the package updates periodically.
- Update the package list daily.
- Download and install security updates daily.
When Does Apt-Daily.Service Perform Updates?
Unless the user’s period is explicitly not set by the user, it executes the install and update process every day triggered by apt-daily.timer.
You can find the configuration file to make changes on it by running the command:
that will give you an output like this:
Description=Daily apt download activities
The red lines show when it tells the system to run the process, 6 AM and 6 PM. Also, you can check the upgrade service run as well with running the following command:
The error itself displays that another process locks the directory. Since the system enables the automatic updates (executes apt-get update) every time, it finishes booting so you can get security updates.
Do I Really Need Apt-daily Service?
If you turn off the apt-daily service, the major drawback is you will need to manually check the updates for packages by using the apt command update. Also, you can set the periodic updates to weekly from daily or set to never. It will direct the system not to attempt automatic updates.
How to Disable Apt-daily Service
You can disable it even though you are not comfortable with the command line terminal under the software and updates page.
- Go to updates and change automatic check for updates to Weekly or Never.
- Restart the system and it will get disabled.
Download a text editor. We will use the nano text editor, which is installed in most of the system. In case your system doesn’t install it, then use the following procedure to do it. You can use the Vi editor as well.
- Run the command $sudo apt update first
- Now, run $sudo apt install nano on Debian/Ubuntu
- $yum install nano on CentOS/Fedora
Now, we will edit the default configuration file for the unattended-upgrades.
Run this command on the nano editor to fetch the configuration file.
After executing the command, you will get an output like this
You need to change these values as given below:
Finally, save the file by pressing CTRL and O then restart the system to make the changes successful.
We hope you understood everything about what is apt Systemd daily. We have thoroughly discussed how you can disable and modify it using the command line and graphical interface. If you liked this guide, check out our official website as we have uploaded hundreds of informative guides like this one.