How to Remove Packages on Ubuntu Linux Command Line

Managing installed packages through the command-line terminal gives you precise control over your Ubuntu system. You will learn how to completely remove unwanted software, clean up orphaned dependencies that consume disk space, and preview removal impacts before making changes. Whether you are troubleshooting a broken installation by removing conflicting packages, freeing up storage after testing multiple applications, or cleaning up after removing PPAs and external repositories, APT (Advanced Package Tool) provides the commands you need to maintain a lean system.

This guide demonstrates removal workflows using concrete examples with expected terminal output at each step. You will see the difference between apt remove and apt purge, how to safely eliminate dependencies left behind after uninstalling packages, and verification commands that confirm clean removal. The techniques shown work identically across all supported Ubuntu LTS releases.

Remove Packages with APT Remove Command

The apt remove command uninstalls a package while preserving its configuration files in /etc/. This approach allows you to reinstall the package later without reconfiguring settings. Use this method when testing different software versions or temporarily removing packages you might need again.

First, remove a package using the standard removal command. The example below removes the telnet client package:

sudo apt remove telnet

After running this command, APT displays which packages will be removed and notifies you of any orphaned dependencies. The output shows packages that were automatically installed as dependencies but are no longer needed:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  inetutils-telnet krb5-locales libk5crypto3 libkeyutils1 libkrb5-3
  libkrb5support0 netbase
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  telnet
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 48.1 kB disk space will be freed.
Do you want to continue? [Y/n]

Type Y and press Enter to confirm the removal. Notice the message about automatically installed packages. These are dependencies left behind that you should clean up using apt autoremove (covered in the next section).

Remove Packages and Configuration Files

Use apt purge instead of apt remove when you want to completely eliminate a package including all configuration files. This ensures no residual settings remain in /etc/ or user home directories. Purging is useful when troubleshooting configuration issues or permanently removing software you will not reinstall.

The command below demonstrates purging the telnet package:

sudo apt purge telnet

The output confirms both package removal and configuration file purging:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  telnet*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 48.1 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 4400 files and directories currently installed.)
Removing telnet (0.17+2.5-3ubuntu4) ...
(Reading database ... 4391 files and directories currently installed.)
Purging configuration files for telnet (0.17+2.5-3ubuntu4) ...

The asterisk (*) next to the package name indicates APT will purge configuration files. The final line confirms successful purging.

Combine Removal and Purge in One Command

You can combine the remove and --purge flag to uninstall and clean configuration files in a single operation:

sudo apt remove --purge telnet

This produces identical results to apt purge and serves as a reminder that you are removing configuration files. Use whichever syntax you find clearer.

Remove Multiple Packages Simultaneously

APT accepts multiple package names in one command, which saves time when uninstalling related software. For example, to remove both telnet and curl together:

sudo apt remove telnet curl

The output lists all packages being removed and calculates total disk space freed:

The following packages were automatically installed and are no longer required:
  inetutils-telnet krb5-locales libbrotli1 libcurl4t64 libgssapi-krb5-2
  libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-common libldap2
  libnghttp2-14 libpsl5t64 librtmp1 libsasl2-2 libsasl2-modules
  libsasl2-modules-db libssh-4 netbase publicsuffix
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  curl telnet
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 582 kB disk space will be freed.

This example shows how removing multiple packages can leave behind many shared dependencies. Always run apt autoremove afterward to clean up orphaned libraries.

Clean Up Orphaned Dependencies with Autoremove

After removing packages, dependencies that APT automatically installed alongside them often remain on your system. These orphaned packages consume disk space unnecessarily and accumulate over time. The apt autoremove command identifies and removes packages that APT installed as dependencies but no longer required by any installed software.

First, check which orphaned packages exist on your system by running autoremove without confirming the removal:

sudo apt autoremove

APT lists packages it will remove and calculates total space this frees:

Review the list carefully before confirming. Once satisfied the packages are safe to remove, type Y and press Enter to proceed with cleanup.

Running apt autoremove regularly prevents orphaned packages from accumulating. Consider using this command after major software removal operations, after removing PPAs or external repositories, or as part of monthly system maintenance routines alongside system cleaning tools. You can also speed up package downloads for future installations.

Remove Package and Dependencies in One Command

Alternatively, combine package removal and dependency cleanup in a single operation by including the package name with apt autoremove. This approach saves time when you know the package and its dependencies are safe to remove. First, preview what will be removed:

apt autoremove --dry-run telnet
Expected Output
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
  inetutils-telnet krb5-locales libk5crypto3 libkeyutils1 libkrb5-3
  libkrb5support0 netbase telnet
0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
After this operation, 1920 kB disk space will be freed.

Review the package list carefully. If satisfied, run the actual removal:

sudo apt autoremove telnet
Expected Output
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
  inetutils-telnet krb5-locales libk5crypto3 libkeyutils1 libkrb5-3
  libkrb5support0 netbase telnet
0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
After this operation, 1920 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 4435 files and directories currently installed.)
Removing telnet (0.17+2.5-3ubuntu4) ...
Removing inetutils-telnet (2:2.5-3ubuntu4) ...
Removing krb5-locales (1.20.1-6ubuntu2.6) ...
Removing libkrb5-3:amd64 (1.20.1-6ubuntu2.6) ...
Removing libk5crypto3:amd64 (1.20.1-6ubuntu2.6) ...
Removing libkeyutils1:amd64 (1.6.3-3build1) ...
Removing libkrb5support0:amd64 (1.20.1-6ubuntu2.6) ...
Removing netbase (6.4) ...
Processing triggers for libc-bin (2.39-0ubuntu8.6) ...

This command removes the specified package plus all orphaned dependencies in one step. The output confirms both the primary package and dependencies APT will eliminate:

The following packages will be REMOVED:
  inetutils-telnet krb5-locales libk5crypto3 libkeyutils1 libkrb5-3
  libkrb5support0 netbase telnet
0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
After this operation, 1920 kB disk space will be freed.

Notice this single command removed 8 packages total (1 primary package + 7 dependencies) and freed nearly 2 MB of disk space. This method works well when you want immediate cleanup without running separate removal and autoremove commands.

Preview Removal Impacts Before Making Changes

Before removing packages, especially system utilities or libraries, you should preview what APT will remove and verify no critical software depends on them. The commands below help you assess removal impacts without making actual changes.

Simulate Package Removal

Use the --dry-run flag to simulate removal without modifying your system. This shows exactly which packages APT would remove:

sudo apt remove --dry-run telnet

The output displays the removal plan without executing it:

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  inetutils-telnet krb5-locales libk5crypto3 libkeyutils1 libkrb5-3
  libkrb5support0 netbase
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  telnet
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Remv telnet [0.17+2.5-3ubuntu4]

This confirms only the telnet package would be removed. Use this technique to verify removal safety before proceeding with actual uninstallation.

Check Package Dependencies and Reverse Dependencies

Before removing a package, identify what other software depends on it using apt-cache rdepends. This prevents accidentally breaking applications that require the package:

apt-cache rdepends telnet

The output lists packages that depend on or recommend the target package:

telnet
Reverse Depends:
  ubuntu-standard
    inetutils-telnet
  ubuntu-standard
    inetutils-telnet
 |zssh
    inetutils-telnet
 |tucnak
    inetutils-telnet
 |ser2net
    inetutils-telnet
  procserv
    inetutils-telnet
 |mininet
    inetutils-telnet
 |matanza
    inetutils-telnet
  libtelnet-utils
    inetutils-telnet
...

In this example, ubuntu-standard depends on the actual telnet implementation. Removing it would not break ubuntu-standard but would remove telnet functionality from the standard Ubuntu package set.

List Files Installed by a Package

To see exactly which files a package installed on your system, use the dpkg -L command:

dpkg -L telnet

The output shows every file the package installed, including binaries, documentation, and configuration locations:

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/telnet
/usr/share/doc/telnet/copyright
/usr/share/doc/telnet/AUTHORS
/usr/share/doc/telnet/NEWS.gz
/usr/share/doc/telnet/THANKS
/usr/share/doc/telnet/changelog.Debian.gz

Knowing which files a package owns helps you understand what removal will eliminate from your system.

Clean APT Package Cache

APT caches downloaded .deb package files in /var/cache/apt/archives/ to enable reinstallation without re-downloading. Over time, this cache grows and consumes disk space. The commands below help you manage cached packages.

Remove Outdated Package Files

Use apt autoclean to remove cached package files that repositories no longer offer (superseded by newer versions):

sudo apt autoclean
Expected Output
Reading package lists...
Building dependency tree...
Reading state information...

The command keeps cached files for currently available package versions while removing obsolete ones. Use autoclean regularly to maintain a reasonable cache size without eliminating all cached packages.

Clear Entire Package Cache

For more aggressive cleanup, use apt clean to remove all cached .deb files:

sudo apt clean

This command frees maximum disk space by clearing the entire package cache: potentially hundreds of megabytes on systems with many installed packages. However, reinstalling or downgrading packages afterward requires re-downloading them.

Verify Cache Cleanup

Confirm the cache directory is empty:

ls /var/cache/apt/archives/
Expected Output
lock  partial

Only the lock file and partial directory remain—all cached .deb packages are removed. Use this command when disk space is critically low or during system maintenance before creating backups.

Troubleshooting Package Removal

Restore Accidentally Removed Packages

If you accidentally removed a package, reinstalling it is straightforward. However, reinstallation does not restore previous configuration files if you used apt purge. Only default configurations are applied.

To reinstall a removed package:

sudo apt install telnet
Expected Output
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  telnet
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 3684 B of archives.
After this operation, 48.1 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu noble/main amd64 telnet all 0.17+2.5-3ubuntu4 [3684 B]
Fetched 3684 B in 1s (4770 B/s)
Selecting previously unselected package telnet.
(Reading database ... 4427 files and directories currently installed.)
Preparing to unpack .../telnet_0.17+2.5-3ubuntu4_all.deb ...
Unpacking telnet (0.17+2.5-3ubuntu4) ...
Setting up telnet (0.17+2.5-3ubuntu4) ...

Verify the reinstallation:

dpkg -l | grep telnet
Expected Output
ii  telnet         0.17+2.5-3ubuntu4    all          basic telnet client

For packages still in the APT cache, this command completes quickly since APT already downloaded the .deb file. If you previously purged the package and need to restore custom configurations, you must reconfigure manually. APT does not back up removed configuration files.

Package Not Found Errors

When attempting to remove a package, you may encounter this error:

E: Unable to locate package example-package

This means the package name doesn’t exist in APT’s database. First, check if it’s actually installed:

dpkg -l | grep example-package
Expected Output (If Installed)
ii  example-package   1.0.0-1ubuntu1   amd64   Description of package

If the output shows “ii” at the start, the package is installed but may have a different name. Search for it:

apt search example

If the package isn’t listed at all, refresh your package database:

sudo apt update
Expected Output
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Fetched 126 kB in 1s (98.5 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done

Try the removal command again with the correct package name. Alternatively, use apt list to verify the exact package name as shown earlier in this guide:

apt list --installed | grep telnet
Expected Output
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

inetutils-telnet/noble,now 2:2.5-3ubuntu4 amd64 [installed,automatic]
telnet/noble,now 0.17+2.5-3ubuntu4 all [installed]

Use the exact package name shown before the forward slash in the removal command. The [installed,automatic] label indicates dependency packages, while [installed] marks manually installed packages.

Essential Package Warnings

Never remove essential system packages such as apt, dpkg, systemd, sudo, or kernel packages (linux-image-*, linux-headers-*). Removing these packages can render your system unbootable or unusable. APT displays warnings when attempting to remove essential packages. Always read these warnings carefully before confirming removal.

Before attempting removal, check whether the package has essential status:

apt-cache show package-name | grep Essential

If this command returns Essential: yes, do not remove the package unless you fully understand the consequences and have a recovery plan.

Broken Dependencies After Removal

After removing packages, you may encounter dependency errors:

You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 package-a : Depends: package-b (>= 1.2.3) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

This happens when removing a package breaks other packages that depend on it. First, check what’s broken:

apt list --installed | grep -E '(broken|not-installed)'

Then fix the dependency issues automatically:

sudo apt install -f
Expected Output
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  package-b
The following NEW packages will be installed:
  package-b
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 125 kB of archives.
After this operation, 512 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Alternatively, use the long form:

sudo apt --fix-broken install

Both commands automatically repair dependency issues by installing missing packages or removing conflicting ones. Verify the fix:

dpkg --audit
Expected Output (If Fixed)
(No output means no issues detected)

Conclusion

You now control package removal on Ubuntu through apt remove, apt purge, and apt autoremove for cleaning orphaned dependencies. Use --dry-run to preview impacts before removing packages, apt autoclean to manage cache storage, and the troubleshooting techniques to recover from accidental deletions. When removing PPA packages, also remove the repository itself for complete cleanup. For the inverse operation, see our guide on updating packages via Ubuntu command line. GUI users may prefer Synaptic Package Manager for visual package management. These commands keep your Ubuntu system lean and prevent dependency conflicts.

Leave a Comment