ElementaryOS 0.4: Avoid "Could not get lock /var/lib/dpkg/lock" on boot

This article will describe a way to avoid "Could not get lock /var/lib/dpkg/lock" on boot (and periodically).

1 Could not get lock /var/lib/dpkg/lock

This error will be caused because other process running dpkg operation like apt command.

$ sudo apt install -y <package>
<snip>
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource
temporarily unavailable)

2 Avoid "Could not get lock /var/lib/dpkg/lock"

So stop apt-daily and apt-daily-upgrades will avoid "Could not get lock /var/lib/dpkg/lock".

$ sudo systemctl mask apt-daily.service
$ sudo systemctl mask apt-daily.timer
$ sudo systemctl mask apt-daily-upgrade.service
$ sudo systemctl mask apt-daily-upgrade.timer
$ # NOTE: AppCenter needs packagekit.
$ # If you need AppCenter, please unmask packagekit.
$ sudo systemctl mask packagekit
$ sudo sed -e 's;^;//;g' -i /etc/apt/apt.conf.d/20packagekit