Reading Time: 5 minutes

In this article, we will be discussing the various methods and techniques used to locate and uninstall the software from a Ubuntu/Debian based server. We will primarily be using the apt and dpkg commands on the command line.

Uninstalling Software Using Apt

Various operating systems utilize different commands for package management that are designed to install and uninstall software. To interact with these packages on Ubuntu, we typically want to use the apt or dpkg commands. You will see these available commands numerous times in the instructions below. Let's get started! 

Locate the Software to Uninstall

Before removing the software, it's also good practice to find and note the entire software title for accuracy. Run the following command and note the name of the software or application. 

root@host:~# apt list -i

Employing the 'apt list' command outputs a full listing of the installed software on the server. This output can be challenging to sort through due to the speed of the output. To remedy this, we will use the 'less' command to locate the software title more easily. This allows us to scroll through the titles, making identifying the software more accessible.

root@host:~# apt list -i | less
Listing...
accountsservice/bionic,now 0.6.45-1ubuntu1 amd64 [installed]
acl/bionic,now 2.2.52-3build1 amd64 [installed]
acpid/bionic,now 1:2.0.28-1ubuntu1 amd64 [installed]
adduser/bionic,bionic,now 3.116ubuntu1 all [installed]
...
...
...
xxd/bionic-updates,bionic-security,now 2:8.0.1453-1ubuntu1.1 amd64 [installed]
xz-utils/bionic,now 5.2.2-1.3 amd64 [installed]
zerofree/bionic,now 1.0.4-1 amd64 [installed]
zlib1g/bionic,now 1:1.2.11.dfsg-0ubuntu2 amd64 [installed]
root@host:~#

Using grep with the apt list command to narrow our search further makes locating installed software even more straightforward.

root@host:~# apt list -i | grep cowsay
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
cowsay/bionic,bionic,now 3.03+dfsg2-4 all [installed]
root@host:~#

In this case, we searched for cowsay. In locating the software, Ubuntu cautions us not to utilize apt within a script due to some irregularities which can occur. We are not using apt in this manner so we can safely ignore this warning. As you can see, the output shows us the title, the version of Ubuntu, the software version, and other details about the application.

Uninstall the Software

Removing software or an application from Ubuntu is relatively simple. In this example, we will show you how to remove the "cowsay" software from Ubuntu. 

root@host:~# apt-get remove cowsay
Reading package lists... Done
Building dependency tree   
Reading state information... Done
The following packages were automatically installed and are no longer required:
 linux-headers-4.15.0-13 linux-headers-4.15.0-13-generic linux-image-4.15.0-13-generic
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
 cowsay
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 89.1 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 126599 files and directories currently installed.)
Removing cowsay (3.03+dfsg2-4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
root@host:~#

Remove and Purge Software

In some cases, configuration files can be left behind after an application is uninstalled. If you want to completely remove the software and any additional config files from your server, we can execute an 'apt-get remove' using the purge flag in the command.

root@host:~# apt-get remove --purge cowsay
Reading package lists... Done
Building dependency tree   
Reading state information... Done
The following packages were automatically installed and are no longer required:
 linux-headers-4.15.0-13 linux-headers-4.15.0-13-generic linux-image-4.15.0-13-generic
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
 cowsay*
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 89.1 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 126599 files and directories currently installed.)
Removing cowsay (3.03+dfsg2-4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
root@host:~#

Remove Dependencies

If you would like to remove any dependencies and libraries associated with the application, you can use the 'apt-get autoremove' cleanup command.

root@host:~# apt-get autoremove
root@host:~# apt autoremove
Reading package lists... Done
Building dependency tree   
Reading state information... Done
The following packages will be REMOVED:
 linux-headers-4.15.0-13 linux-headers-4.15.0-13-generic linux-image-4.15.0-13-generic
0 upgraded, 0 newly installed, 3 to remove and 1 not upgraded.
After this operation, 163 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 126541 files and directories currently installed.)
Removing linux-headers-4.15.0-13-generic (4.15.0-13.14) ...
Removing linux-headers-4.15.0-13 (4.15.0-13.14) ...
Removing linux-image-4.15.0-13-generic (4.15.0-13.14) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.15.0-13-generic /boot/vmlinuz-4.15.0-13-generic
update-initramfs: Deleting /boot/initrd.img-4.15.0-13-generic
run-parts: executing /etc/kernel/postrm.d/x-grub-legacy-ec2 4.15.0-13-generic /boot/vmlinuz-4.15.0-13-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-4.15.0-74-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Found kernel: /boot/vmlinuz-4.15.0-13-generic
Replacing config file /run/grub/menu.lst with new version
Found kernel: /boot/vmlinuz-4.15.0-74-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done

run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.15.0-13-generic /boot/vmlinuz-4.15.0-13-generic
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-74-generic
Found initrd image: /boot/initrd.img-4.15.0-74-generic
Found linux image: /boot/vmlinuz-4.15.0-72-generic
Found initrd image: /boot/initrd.img-4.15.0-72-generic
done
root@host:~#

In this case, there were no specific dependencies that relate to the software. Still, the system did note an old kernel version and removed it and then updated the system with a newer kernel version automatically. 

Uninstalling Software Using dpkg

The second method we can employ to uninstall software is by using the dpkg command. dpkg can also be utilized to locate and remove installed software.

root@host:~# dpkg --remove package-name

To remove a .deb file, we can use the "-r" flag like so:

root@host:~# dpkg -r package.deb

To choose from the full list of installed packages, we use the "-l" flag with dpkg to get a complete roster of software that is currently deployed on the server. We can also pipe the output of this command into 'less' to make searching for the software title easier.

root@host:~# dpkg-query -l | less

To narrow our search even further, we can pipe the output of the dpkg-query command into a grep to locate the installed software.

root@host:~# dpkg-query -l | grep cowsay
ii cowsay 3.03+dfsg2-4 all configurable talking cow
root@host:~#

Lastly, if we only know a part of the name of the software title we want to uninstall, we can use the grep command with the part of the name denoted within a pair of single quotes. This request will search the output of the dpkg-query and output a shortlist of available options like so:

root@host:~# dpkg-query -l | grep partial_name'

root@host:~# dpkg-query -l | grep 'cow'
ii cowsay 3.03+dfsg2-4 all configurable talking cow
root@host:~#

That's all there is to it! You now know multiple ways to locate and uninstall the software from a Ubuntu server.

We’d Love For You To Join Us!

In this time of rapid technological advancement, Liquid Web provides more than just the widest selection of hosting products and services. We devote our time, talent and experience to you. We define ourselves as the being The Most Helpful Humans In Hosting® because we believe that the more you need technology to drive your business, the more you need expert, caring people to stand by your side.

Give us a call at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable Solutions Team or an experienced Hosting Advisors today to find out more!

Avatar for Alison Gray

About the Author: Alison Gray

Alison Gray is currently an IT Project Manager at Liquid Web and has been with Liquid Web for nearly 10 years. In 2015, She earned her Bachelor's Degree in Media and Information from Michigan State University. In her free time, she loves spending time with her girlfriend and 3 kids. You can usually find her at a basketball court or some sort of sporting event. If the weather's right, she loves being outside in the yard finding some sort of yard work to do.

Latest Articles

Blocking IP or whitelisting IP addresses with UFW

Read Article

CentOS Linux 7 end of life migrations

Read Article

Use ChatGPT to diagnose and resolve server issues

Read Article

What is SDDC VMware?

Read Article

Best authentication practices for email senders

Read Article