How to solve the error: WARNING:root:could not open file ‘/etc/apt/sources.list’. The sources.list is the list of configured APT data sources and sometimes it show the warning that root:could not open file ‘/etc/apt.
sources.list
sources.list is the list of configured APT data sources. The source list /etc/apt/sources.list is designed to support any number of active sources and a variety of source media. The file lists one source per line, with the most preferred source listed first. The information available from the configured sources is acquired by apt-get update (or by an equivalent command from another APT front-end).
Each line specifying a source starts with type (e.g. deb-src) followed by options and arguments for this type. Individual entries cannot be continued onto a following line. Empty lines are ignored, and a # character anywhere on a line marks the remainder of that line as a comment
Method 1
This happens when the directory /etc/apt/sources.list.d doesn’t have the execute permissions (denoted by x). The permission is needed to open a directory. SO to restore the execute permission, run the command:
sudo chmod +x /etc/apt/sources.list.d
Changing the permissions can also be executed by the following command:
sudo chmod -R 0644 /etc/apt/sources.list.d/
Method 2
You can also work on the sources.list file to renew the configuration:
rm /etc/atp/sources.list.d /etc/atp/sources.list
Also note that sources.list files are in /etc/apt/sources.list.d. So to use it, you will need to make a symbolic link from official-package-repositories.list to the old one. Do this by executing the following command :
sudo ln -s /etc/apt/sources.list.d/official-package-repositories.list /etc/apt/sources.list