How to completely remove a package in Ubuntu

In general, when you install any package in Linux the dependency packages also get installed alongside.

Dependency packages are necessary to run a application without any issues.

When the package is uninstalled, the dependency packages will stay on the system. These leftover packages are no longer used by anything and it is safe to remove them.

Identifying a package in Ubuntu

We should be knowing the exact package name to uninstall it. The package can be identified using the ‘apt’ command and we should be aware few letters about a package which can help to identify the package easily instead of checking all of them on the system.

Using apt command

$ apt list --installed | grep nginx

libnginx-mod-http-image-filter/focal-updates,now 1.18.0-0ubuntu1 amd64 [installed,automatic]
libnginx-mod-http-xslt-filter/focal-updates,now 1.18.0-0ubuntu1 amd64 [installed,automatic]
libnginx-mod-mail/focal-updates,now 1.18.0-0ubuntu1 amd64 [installed,automatic]
libnginx-mod-stream/focal-updates,now 1.18.0-0ubuntu1 amd64 [installed,automatic]
nginx-common/focal-updates,focal-updates,now 1.18.0-0ubuntu1 all [installed,automatic]
nginx-core/focal-updates,now 1.18.0-0ubuntu1 amd64 [installed,automatic]
nginx/focal-updates,focal-updates,now 1.18.0-0ubuntu1 all [installed]

Using dpkg command

$ dpkg -l | grep nginx

ii  libnginx-mod-http-image-filter             1.18.0-0ubuntu1                          amd64        HTTP image filter module for Nginx
ii  libnginx-mod-http-xslt-filter              1.18.0-0ubuntu1                          amd64        XSLT Transformation module for Nginx
ii  libnginx-mod-mail                          1.18.0-0ubuntu1                          amd64        Mail module for Nginx
ii  libnginx-mod-stream                        1.18.0-0ubuntu1                          amd64        Stream module for Nginx
ii  nginx                                      1.18.0-0ubuntu1                          all          small, powerful, scalable web/proxy server
ii  nginx-common                               1.18.0-0ubuntu1                          all          small, powerful, scalable web/proxy server - common files
ii  nginx-core                                 1.18.0-0ubuntu1                          amd64        nginx web/proxy server (standard version)

1) Removing a package using apt command

apt is a command-line utility for installing, updating, and removing deb packages on Ubuntu, Debian, and their derivatives. It combines the most commonly used commands from the apt-get and apt-cache.

The below command is used to remove the binaries, but not the configuration or data files of the package. It will also leave dependencies associated with it.

$ sudo apt remove packagename

The following command removes the package including all its files but not the dependencies installed with it.

$ sudo apt purge packagename
$ sudo apt remove --purge packagename

Run the below command to remove orphaned packages.

$ sudo apt autoremove

2) Removing a package using apt-get command

apt-get is a CLI package management tool that is widely used on Debian based systems. The apt-get command allows us to Install, update, and remove packages, while the apt-cache command is used to search for new packages.

Run the following commands to completely remove a package from the system.

$ sudo apt-get remove packagename
$ sudo apt-get purge packagename
$ sudo apt-get autoremove

3) Removing manually installed package

If you had installed a package using make file, it will be uninstalled in the same procedure. Please navigate to the package directory and follow the below steps to remove it.

For demonstration purposes, we will be uninstalling the node package using the make file.

$ pwd

$ ./configure
$ make
$ make uninstall
$ node -v
bash: /usr/local/bin/node: No such file or directory

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

2 Comments on “How to completely remove a package in Ubuntu”

  1. i installed metasploit on my linux mint and i want to unstall it and unstall all it package n folders.. which command should i use, am runing linux mint 17.3 Cinnamon

    1. Solomon,
      Navigate to package download folder (path/metasploit-x.x.x) and execute $ sudo /path/metasploit-x.x.x/uninstall then finally remove the folder too $ sudo rm -Rf /path/metasploit-x.x.x

Leave a Reply

Your email address will not be published. Required fields are marked *