This question is an obvious updated version of How do I remove a malformed line from my sources.list?. In Ubuntu 24.04 and later Ubuntu software sources have been moved to /etc/apt/sources.list.d/ubuntu.sources
. The objective of this question is to get at least one updated answer that is suitable for merging into the original canonical question.
As a starting point here is what the default ubuntu.sources file looks like in Ubuntu 24.04.
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
These instructions are compatible with Ubuntu 24.04 and later in which software sources are located in separate files that are located under the
/etc/apt/sources.list.d/
directory.Identify the file which contains the malformed line.
The error message you encounter will typically point you to the specific file containing the malformed line. It might look something like this.
In this example
/etc/apt/sources.list.d/additional-repo.list
is the file with the line that is referred to by themalformed line
error message.Back up the file before making changes with
cp /etc/apt/sources.list.d/<filename> /etc/apt/sources.list.d/<filename>.bak
Open the file for editing with root privileges.
Use a text editor that runs in the terminal like
nano
to edit the file. Replace<filename>
with the file identified in step 1 in the following command.Locate and remove the malformed line.
In the opened file look for lines that appear malformed compared to the standard format.
Here are examples of correctly formatted lines for reference:
Anything that doesn't follow this format is likely to be incorrect.
Use the arrow keys to navigate and position the cursor on the malformed line and insert a
#
character at the beginning of the line to turn it into a comment.Save the file being edited and exit from nano.
Update the package lists by running
sudo apt update