How To Uninstall In Linux – Using Terminal To Uninstall Linux Packages

Linux software removal typically uses the terminal with commands like `sudo apt remove`. If you are new to Linux, uninstalling programs might feel confusing because it is not always as simple as dragging an icon to the trash. This guide will show you exactly how to uninstall in Linux using different methods, from the command line to graphical tools.

We will cover package managers like APT, DNF, and Pacman, plus snap and flatpak removal. You will also learn how to handle dependencies and remove leftover config files. By the end, you will be confident cleaning up your system.

How To Uninstall In Linux

Uninstalling software in Linux depends on how you installed it. Most distributions use a package manager. The most common ones are APT (Debian/Ubuntu), DNF (Fedora), and Pacman (Arch). Each has its own commands.

You can also uninstall via the software center or by removing flatpak and snap packages. Let us break down each method step by step.

Using APT To Remove Packages On Debian Or Ubuntu

APT is the default package manager for Debian-based systems. To uninstall a package, you use the `apt remove` command. First, open a terminal by pressing Ctrl+Alt+T.

  1. Type sudo apt remove package-name and press Enter.
  2. Replace “package-name” with the actual name of the software.
  3. Enter your password when prompted.
  4. Confirm the removal by typing Y when asked.

For example, to remove Firefox, you would run sudo apt remove firefox. This removes the program but leaves configuration files behind. If you want to delete those too, use sudo apt purge package-name.

To clean up unused dependencies that were installed with the package, run sudo apt autoremove. This frees up disk space and keeps your system tidy.

Checking What Packages Are Installed

If you are not sure of the exact package name, you can list installed packages. Use apt list --installed to see everything. You can also search with apt search keyword to find the correct name.

Another handy command is dpkg -l which shows a list of all packages. Look for the one you want to remove and note its name.

Removing Software With DNF On Fedora

Fedora uses DNF as its package manager. The process is similar to APT. Open a terminal and type sudo dnf remove package-name. This will uninstall the package and its dependencies that are no longer needed.

For example, to remove the GIMP image editor, run sudo dnf remove gimp. DNF will ask for confirmation. Type Y and press Enter.

To remove leftover configuration files, you can use sudo dnf remove --setopt=clean_requirements_on_remove=true package-name. But usually, the default removal is enough.

You can also list installed packages with dnf list installed. This helps you find the exact name if you forgot it.

Using Pacman On Arch Linux

Arch Linux uses Pacman. To uninstall a package, use sudo pacman -R package-name. The `-R` flag stands for remove. For instance, sudo pacman -R vlc removes the VLC media player.

If you want to remove the package along with its dependencies that are not needed by other software, add the `-s` flag: sudo pacman -Rs package-name. This is the recommended way to keep your system clean.

To also remove configuration files, use `-n`: sudo pacman -Rns package-name. This is thorough but be careful because you might lose custom settings.

List installed packages with pacman -Q. You can also search with pacman -Qs keyword.

Uninstalling Snap Packages

Snap packages are installed from the Snap Store. To remove a snap, use the `snap remove` command. Open a terminal and type sudo snap remove package-name.

For example, sudo snap remove spotify will uninstall the Spotify snap. You do not need to worry about dependencies because snaps are self-contained.

To list all installed snaps, run snap list. This shows the version and other details.

Removing Flatpak Applications

Flatpak is another universal packaging system. To uninstall a flatpak, use flatpak uninstall package-name. You might need to use the full application ID, which you can find with flatpak list.

For example, to remove the Telegram desktop app, run flatpak uninstall org.telegram.desktop. Flatpak will ask for confirmation.

You can also remove unused runtimes with flatpak uninstall --unused. This cleans up leftover libraries that are no longer needed.

Using The Software Center Or GUI

If you prefer a graphical interface, most Linux distributions have a software center. On Ubuntu, it is called Ubuntu Software. On Fedora, it is GNOME Software. You can open it from the applications menu.

  1. Open the software center.
  2. Click on the “Installed” tab or search for the app.
  3. Find the program you want to remove.
  4. Click the “Remove” button next to it.
  5. Enter your password if prompted.

This method is straightforward and does not require terminal commands. However, it may not remove all configuration files. For a complete cleanup, use the terminal method.

Removing Dependencies And Leftover Files

When you uninstall a package, some dependencies might remain. These are libraries that were installed with the software but are not used by anything else. Over time, they can clutter your system.

For APT, use sudo apt autoremove after removing a package. For DNF, use sudo dnf autoremove. For Pacman, the `-Rs` flag handles this automatically.

You can also remove orphaned packages with sudo apt autoclean or sudo dnf clean all. This clears cached package files.

Configuration files left behind can be found in your home directory. Look in hidden folders like ~/.config or ~/.local/share. You can delete these manually if you are sure you do not need them.

Uninstalling Software Installed From Source

If you compiled software from source code, removal is trickier. There is no standard uninstall command. The source code usually includes a Makefile with an uninstall target.

Navigate to the source directory and run sudo make uninstall. This might work if the developer included it. If not, you have to manually delete the files.

To find where the files were installed, check the Makefile or use find command. For example, find /usr -name "*program-name*" can locate the files. Be careful not to delete system files.

It is better to avoid installing from source unless necessary. Use package managers or flatpak/snap instead for easier removal.

Removing Kernels And Old Versions

Linux kernels can accumulate over time. Old kernels take up space and may cause boot issues. To remove them, you can use the package manager.

On Ubuntu, list installed kernels with dpkg --list | grep linux-image. Then remove old ones with sudo apt purge linux-image-x.x.x-x-generic. Keep at least one older kernel as a backup.

On Fedora, use sudo dnf remove kernel-core-version. On Arch, use sudo pacman -R linux-version. Always keep the current kernel.

You can also use tools like ubuntu-mainline-kernel.sh or kernel-install for automated management.

Using Wildcards To Remove Multiple Packages

Sometimes you want to remove several packages at once. You can use wildcards with the package manager. For example, sudo apt remove 'lib*' would remove all packages starting with “lib”. Be very careful with this because it can break your system.

It is safer to list the packages first. On APT, you can use apt list --installed | grep pattern to see what matches. Then remove them one by one or in a list.

For DNF, use sudo dnf remove package1 package2 package3. For Pacman, sudo pacman -R package1 package2.

Common Mistakes And How To Avoid Them

One common mistake is removing a package that other software depends on. This can break your system. Always check what will be removed before confirming.

Another mistake is forgetting to use sudo. Most package management commands require root privileges. If you get a permission error, add sudo at the beginning.

Also, do not remove packages like apt, dpkg, or systemd. These are essential for the system to function. Stick to removing user-installed software.

If you accidentally remove something important, you can reinstall it with the same package manager. For example, sudo apt install package-name.

Checking For Dependencies Before Removal

Before removing a package, you can see what depends on it. On APT, use apt depends package-name. This shows a tree of dependencies.

On DNF, use dnf repoquery --requires package-name. On Pacman, use pacman -Qi package-name and look at “Required By”.

This helps you avoid breaking other software. If something important depends on the package, consider keeping it.

Using Aliases To Speed Up Uninstall

If you uninstall software often, you can create aliases in your shell. For example, add this to your ~/.bashrc file:

alias uninstall='sudo apt remove'

Then you can just type uninstall package-name. This saves time. You can create aliases for other package managers too.

Remember to reload the file with source ~/.bashrc after editing.

Uninstalling With Yum On Older Systems

Some older distributions use Yum instead of DNF. The command is sudo yum remove package-name. It works similarly to DNF.

You can also use sudo yum autoremove to clean up dependencies. Yum is being replaced by DNF, but it is still found on CentOS 7 and similar.

Removing Packages From Third-Party Repositories

If you added a third-party repository, you can remove packages from it the same way. Just use the package manager commands. However, the repository itself may need to be removed separately.

To remove a repository on Ubuntu, edit the /etc/apt/sources.list file or files in /etc/apt/sources.list.d/. Comment out or delete the line. Then run sudo apt update.

On Fedora, use sudo dnf config-manager --set-disabled repository-name. On Arch, edit /etc/pacman.conf or remove files in /etc/pacman.d/.

Using Graphical Tools For Removal

Besides the software center, there are other GUI tools. Synaptic Package Manager is a popular one for Debian/Ubuntu. Install it with sudo apt install synaptic.

Open Synaptic, search for the package, right-click it, and choose “Mark for Removal”. Then click “Apply”. This gives you more control over dependencies.

On Fedora, you can use the “Add/Remove Software” tool. It is similar to the software center but more detailed.

Removing Snap And Flatpak Leftovers

After uninstalling snaps, some data might remain in /var/lib/snapd or ~/snap. You can delete these folders manually if you want a clean removal.

For flatpak, leftover data is in ~/.local/share/flatpak or /var/lib/flatpak. Use flatpak uninstall --unused to remove unneeded runtimes.

Be careful when deleting system directories. Only remove what you are sure about.

Automating Cleanup With Scripts

You can write a simple script to automate uninstall and cleanup. For example, a bash script that removes a package and then runs autoremove:

#!/bin/bash
sudo apt remove "$1"
sudo apt autoremove

Save it as uninstall.sh, make it executable with chmod +x uninstall.sh, and run it with ./uninstall.sh package-name.

This saves time if you uninstall frequently.

What To Do If Uninstall Fails

Sometimes the package manager might fail due to broken dependencies or locked databases. First, try sudo apt --fix-broken install on Debian/Ubuntu. This repairs broken packages.

On Fedora, use sudo dnf check or sudo dnf distro-sync. On Arch, use sudo pacman -Syu to update and then try again.

If the database is locked, wait for other processes to finish or reboot. You can also remove the lock file manually, but that is risky.

Conclusion

Now you know how to uninstall in Linux using various methods. Whether you prefer the terminal or a graphical interface, the process is straightforward once you understand the commands. Always check dependencies and clean up leftovers to keep your system healthy.

Practice on a test system if you are unsure. With time, uninstalling software will become second nature. Remember to use sudo and confirm before removing packages.

Frequently Asked Questions

How Do I Uninstall A Program In Linux Terminal?

Use the package manager command for your distribution. For Ubuntu, it is sudo apt remove package-name. For Fedora, sudo dnf remove package-name. For Arch, sudo pacman -R package-name.

What Is The Difference Between Remove And Purge In APT?

apt remove deletes the program but keeps configuration files. apt purge removes both the program and its config files. Use purge if you want a clean slate.

Can I Uninstall Linux Itself?

Yes, if you want to remove Linux from a dual-boot system, you can delete its partitions from Windows or another OS. Use a tool like GParted or the Windows Disk Manager. Be careful not to delete important data.

How Do I Uninstall Snap Packages?

Use sudo snap remove package-name. List installed snaps with snap list to find the correct name. Snaps are self-contained, so no dependencies to worry about.

Why Does Uninstalling Leave Files Behind?

Package managers often keep configuration files in case you reinstall the software later. You can remove them manually or use purge commands. Dependencies might also remain if they are shared with other programs.