This error occurs when one or more files in your apt sources directory contain syntax errors or malformed entries. Identifying and fixing the problematic source file restores apt functionality.
The apt package manager reads repository source configuration from /etc/apt/sources.list and files in /etc/apt/sources.list.d/. When these files contain malformed entries—syntax errors, invalid URIs, or broken formatting—apt cannot parse them during update or install operations. This prevents apt from accessing any software repositories until the broken source file is corrected or removed.
Run the diagnostic command:
sudo apt-get checkThis will output which file contains the malformed entry, for example:
E: Malformed entry 1 in sources file /etc/apt/sources.list.d/rethinkdb.list (Component)
E: The list of sources could not be readNote the file path and line number mentioned in the error.
Use a text editor to open the file identified in the previous step:
sudo nano /etc/apt/sources.list.d/rethinkdb.listIf the error is in the main sources list, edit:
sudo nano /etc/apt/sources.listLook at the line number mentioned in the error. Check for:
- Missing or extra spaces
- Incomplete repository URL
- Invalid component name
- Missing distribution codename
A valid source line looks like:
deb https://archive.ubuntu.com/ubuntu/ bionic main universe multiverseEither fix the syntax or delete the entire line if you don't recognize the repository.
Save the file (in nano: Ctrl+O, then Ctrl+X).
Run apt-get check again:
sudo apt-get checkIf the error is gone, continue to the next step. If the same file is still reported, check for additional broken lines.
Now rebuild the package cache with:
sudo apt updateThis downloads fresh package lists from all configured sources. The error should not appear.
If the file contains only a third-party repository you no longer need, remove it entirely:
sudo rm /etc/apt/sources.list.d/rethinkdb.list
sudo apt updateDo NOT remove /etc/apt/sources.list itself, as it contains the main Ubuntu/Debian repositories. Only remove files in the .d/ directory if they are causing issues.
You can view all currently configured sources with apt-cache policy or by listing the entire sources.list.d directory: ls /etc/apt/sources.list.d/. If multiple files are broken, use grep -r "^deb" /etc/apt/sources.list.d/ to inspect all of them. For PPA sources added via add-apt-repository, use sudo add-apt-repository --remove ppa:username/ppaname to cleanly remove them instead of manually editing. After fixing sources, if you see "Failed to fetch" errors, the repository URL may be down or your network connection may be unreachable—verify the URL is current and accessible before reporting it as broken.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT