How to Purge Packages from a Specific Source in Ubuntu

How to Purge Packages from a Specific Source in Ubuntu
💡
Warning: This can break the system, make sure you create system backups using timeshift or Borg backup tools before attempt making system-level changes.

Sometimes, you may want to uninstall all the packages you installed from a specific repository in Ubuntu, for example, if you no longer need them or if they cause issues on your system. We will go through the steps that use different methods to remove packages for different repositories.

PPA repositories

PPA repositories are Personal Package Archives that provide packages unavailable in the official Ubuntu repositories. To remove all packages from a PPA repository, you can use the ppa-purge command, downgrading the packages to the versions available in the official repositories.

To use ppa-purge, you need to install it first:

sudo apt install ppa-purge

Then, you can run it with the name of the PPA repository as an argument:

sudo ppa-purge ppa:ppaowner/ppaname

For example, if you want to remove all packages from the LibreOffice PPA repository, you can run the following:

sudo ppa-purge ppa:libreoffice/ppa

This will uninstall all packages from the LibreOffice PPA and restore the default LibreOffice version provided by Ubuntu.

Other repositories

Suppose you have added other repositories that are not PPA repositories, such as third-party or custom repositories. In that case, you can use the aptitude command to list and remove all packages from them.

To use aptitude, you need to install it first:

sudo apt install aptitude

Then, you can list all the installed packages that are available from a specific repository using this syntax:

aptitude search '~O"Repository Name" ~i'

For example, if you want to list all packages from the NodeSource repository, you can run:

aptitude search '~O"Node Source" ~i'

This will show you all the installed packages with “Node Source” origin. For each package, you can check which version is installed and note those which are installed from the repository you wish to remove.

Then, you can purge all those packages using the apt purge command:

sudo apt purge package1 package2 package3 ...

For example, if you want to purge all packages from the NodeSource repository and they are nodejs and nodejs-dbg, you can run:

sudo apt purge nodejs nodejs-dbg

This will uninstall all packages from the NodeSource repository and remove all their dependencies and configuration files.

Finally, you can remove the repository by deleting its entry from the /etc/apt/sources.list file or the repository file in the /etc/apt/sources.list.d directory.

You can use any text editor to do that, such as Nano or Gedit. For example, if you want to remove the NodeSource repository entry from /etc/apt/sources.list.d/nodesource.list, you can run the following:

sudo nano /etc/apt/sources.list.d/nodesource.list

Then, delete the line that starts with deb https://deb.nodesource.com/node_8.x … and save and exit the file.

Alternatively, you can use the add-apt-repository command with the -r Option to remove a repository entry:

sudo add-apt-repository -r "deb https://deb.nodesource.com/node_8.x ..."

This will delete the corresponding entry from /etc/apt/sources.list or /etc/apt/sources.list.d.

After removing any repository, you should update your package lists with:

sudo apt update

This will refresh your system’s knowledge of what packages are available from what sources.

This can help you clean up your system and avoid potential conflicts or problems caused by outdated or incompatible packages. If you have any questions or suggestions please feel free to leave a comment below.