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 or $ 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 /opt/node-v14.15.4 $ ./configure $ make $ make uninstall $ node -v bash: /usr/local/bin/node: No such file or directory