When you use add-apt-repository non-free, you're not adding a new, external repository in the way you would a PPA. Instead, you're usually uncommenting or adding the non-free component to your existing Debian/Ubuntu repository lines in your sources.list file or creating a small .list file in /etc/apt/sources.list.d/.
Here's how to remove it, depending on how it was added:
The Most Common Scenario (and Recommended Method): Manually Editing sources.list or a File in sources.list.d
This is the most reliable way to ensure the non-free component is no longer used.
-
Identify the relevant file(s):
- Check
/etc/apt/sources.list.d/ first:
ls /etc/apt/sources.list.d/
Look for files that might contain "non-free" in their name or content, e.g., debian.list, official-package-repositories.list, or something like non-free.list.
- Check
/etc/apt/sources.list:
sudo nano /etc/apt/sources.list
-
Edit the file(s) to remove or comment out the non-free entry:
Once you've found the file, open it with a text editor (e.g., nano or vim).
sudo nano /etc/apt/sources.list
OR
sudo nano /etc/apt/sources.list.d/your-repo-file.list (replace your-repo-file.list with the actual filename you found)
Look for lines that include non-free. They will typically look something like this:
deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
# deb-src http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
or
deb http://deb.debian.org/debian/ bookworm non-free
To remove non-free:
- If
non-free is on the same line as main and contrib: Simply delete non-free (and non-free-firmware if it's there) from the line.
- Before:
deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
- After:
deb http://deb.debian.org/debian/ bookworm main contrib
- If
non-free is on its own line: Comment out the line by adding a # at the beginning, or delete the entire line.
- Before:
deb http://deb.debian.org/debian/ bookworm non-free
- After:
# deb http://deb.debian.org/debian/ bookworm non-free (or delete the line)
Save the file (Ctrl+O, Enter, Ctrl+X in nano).
-
Update your package lists:
After making changes to your sources.list files, you must update Apt's cache:
sudo apt update
This will remove the packages from the non-free component from your available package lists.
Less Common Scenario: Using add-apt-repository --remove (Less likely for official components)
The add-apt-repository --remove command is primarily designed for removing PPAs (Personal Package Archives). It typically doesn't work for official distribution components like non-free unless add-apt-repository created a specific .list file for it in /etc/apt/sources.list.d/ using a PPA-like naming convention, which is rare for non-free.
You can try it, but don't expect it to work for official Debian/Ubuntu components:
sudo add-apt-repository --remove non-free
If it says something like "Repository 'non-free' not found," then this method didn't work, and you'll need to use the manual editing method above.
What Happens After Removal?
- No new
non-free packages: You will no longer be able to install new packages from the non-free repository.
- Installed
non-free packages remain: Any packages you previously installed from non-free will not be automatically removed. They will simply stop receiving updates from the non-free repository.
- Removing installed
non-free packages: If you want to remove specific packages that you know came from non-free (e.g., certain firmware, drivers, codecs), you'll need to uninstall them explicitly:
sudo apt remove package-name
You can then run sudo apt autoremove to remove any no-longer-needed dependencies.