How to fix E: Malformed line 1 in source list /etc/apt/sources.list in APT

APTBEGINNERHIGHUpdated Dec 29, 2025ยท 377 views

This error occurs when APT detects a syntax error in your sources.list file or files in sources.list.d/. Common causes include malformed URLs, incorrect line breaks, and mixed format styles. The fix involves identifying and correcting the problematic line.

Quick fix

Fixes E: Malformed line 1 in source list /etc/apt/sources.list

E: Malformed line 5 in source list /etc/apt/sources.list
  1. Identify the problematic file and line number
  2. Open the file in a text editor
  3. Examine the problematic line and fix the syntax
  4. Save the file and verify the fix
apt โ€” error
E: Malformed line 5 in source list /etc/apt/sources.list
E: Malformed line 1 in source list /etc/apt/sources.list

What this error means

The APT package manager reads repository configurations from /etc/apt/sources.list and files in /etc/apt/sources.list.d/ directory. When it encounters a line that doesn't follow the correct syntax, it reports this error with the line number and location. Each repository line must follow the Debian package repository format: `deb [options] uri distribution [component1] [component2]`. If a line has incorrect URL formatting, missing components, unescaped special characters, or spans multiple lines when it shouldn't, APT cannot parse it and raises this error.

Typical symptoms

  • apt update fails immediately with malformed line error
  • apt install or apt upgrade commands fail to run
  • Package manager becomes completely non-functional
  • Error message specifies the exact line number causing the problem

Common causes

  1. Incorrect URL formatting or typos in repository addresses (extra slashes, missing components)
  2. Line breaks or text wrapping in what should be a single-line entry when adding repositories
  3. Unescaped special characters or brackets in the repository URL
  4. Mixing old .list format with newer .sources format in the same file
  5. Invalid file extensions (like .backup) in the sources.list.d/ directory
  6. Extra spaces or missing spaces between repository components
  7. Copy-paste errors when adding new repositories from documentation

How to fix "E: Malformed line 1 in source list /etc/apt/sources.list"

1Identify the problematic file and line number

The error message tells you which file and line number has the problem:

bash
E: Malformed line 5 in source list /etc/apt/sources.list

or

bash
E: Malformed line 1 in source list /etc/apt/sources.list.d/docker.list

Note the line number and file path from the error message.

2Open the file in a text editor

Open the problematic sources file with a text editor:

bash
sudo nano /etc/apt/sources.list

Or if the error mentions a file in sources.list.d/:

bash
sudo nano /etc/apt/sources.list.d/filename.list

Use nano, vim, or your preferred text editor.

3Examine the problematic line and fix the syntax

Look at the line number mentioned in the error. Check for these common issues:

Correct format:

bash
deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse

Common mistakes to fix:

1. Extra slashes or incorrect URLs:

bash
# WRONG - extra slash
   deb http://archive.ubuntu.com//ubuntu focal main

   # CORRECT
   deb http://archive.ubuntu.com/ubuntu focal main

2. Missing components or spaces:

bash
# WRONG - missing space between URL and distribution
   deb http://archive.ubuntu.comainter focal main

   # CORRECT
   deb http://archive.ubuntu.com/ubuntu focal main

3. Line wrapped incorrectly:

bash
# WRONG - split across lines
   deb http://archive.ubuntu.com/ubuntu
   focal main restricted

   # CORRECT - single line
   deb http://archive.ubuntu.com/ubuntu focal main restricted

4. Extra or stray characters:

bash
# WRONG - extra text at end
   deb http://archive.ubuntu.com/ubuntu focal main restricted] EXTRA

   # CORRECT
   deb http://archive.ubuntu.com/ubuntu focal main restricted

If you can't determine what's wrong, you can safely comment out the problematic line by adding # at the beginning:

bash
# deb http://archive.ubuntu.com/ubuntu focal main
4Save the file and verify the fix

Save your changes:
- In nano: Press Ctrl+X, then Y to confirm, then Enter to save
- In vim: Press Esc, type :wq, and press Enter

Then test that APT can read the file correctly:

bash
sudo apt update

If the error is gone and apt update completes successfully, the problem is fixed.

5Check for malformed files in sources.list.d/

If the error is in the main sources.list file but you've fixed all lines, check for problematic files in sources.list.d/:

bash
ls -la /etc/apt/sources.list.d/

Look for files with incorrect extensions (like .backup, .bak, .old). APT only recognizes:
- .list files (old format)
- .sources files (new DEB822 format)

Delete or rename any backup files:

bash
sudo rm /etc/apt/sources.list.d/old-repo.backup

Then try sudo apt update again.

Advanced notes

About the two APT source formats:

APT supports two different source list formats:

1. One-line format (.list files): The traditional format using a single line:

bash
deb [options] uri distribution [components]

2. DEB822 format (.sources files): The newer RFC 822 style format introduced in Debian 12 and Ubuntu 22.04+:

bash
Types: deb
   URIs: http://archive.ubuntu.com/ubuntu
   Suites: focal
   Components: main restricted universe multiverse

Don't mix these formats in the same file. If you're migrating, create separate .sources files for new repositories.

Checking file syntax with apt-listchanges:

You can validate your sources without running a full update using:

bash
sudo apt-get check

This performs sanity checks on the repository configuration without downloading package lists.

Frequently asked questions

What does "E: Malformed line 1 in source list /etc/apt/sources.list" mean?
d/ directory. When it encounters a line that doesn't follow the correct syntax, it reports this error with the line number and location. Each repository line must follow the Debian package repository format: deb [options] uri distribution [component1] [component2].
How do I fix "E: Malformed line 1 in source list /etc/apt/sources.list"?
This error occurs when APT detects a syntax error in your sources.list file or files in sources.list.d/. Common causes include malformed URLs, incorrect line breaks, and mixed format styles. The fix involves identifying and correcting the problematic line.
What causes "E: Malformed line 1 in source list /etc/apt/sources.list"?
Incorrect URL formatting or typos in repository addresses (extra slashes, missing components) Line breaks or text wrapping in what should be a single-line entry when adding repositories Unescaped special characters or brackets in the repository URL
Is the "E: Malformed line 1 in source list /etc/apt/sources.list" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading