Suppose I download a .deb package from a website and install it. (I assume that when I double click the .deb file, the package is installed through a GUI that interfaces with dpkg right?)
How can I uninstall it?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
Manually installed packages appear in the Software Centre, along with all the others. Just search the software centre for your package and remove it there.
You may have to click on "Show N technical items"
Along with this, there are a few other methods:
Click the Apply button.
This will have the benefit of listing all of your manually installed packages:
You can either use
sudo apt-get remove packagename if you know the name of the package, or if you don't, search for it using
apt-cache search crazy-app and then remove it using apt get
You can also use
dpkg --remove packagename.
This will also let you know if there are any unneeded packages left on your system, which were possibly installed as dependencies of your .deb package. Use
sudo apt-get autoremove to get rid of them.
See this blogpost for more information.
Every solution here assumes you know or can find the name of the package, but none provide how to remove a package if all you have is the deb. To that end, the below command will extract the package name from the deb and remove that package name.
dpkg -r $(dpkg -f your-file-here.deb Package)
NB: this does not confirm that the package being removed is the exact version described by the deb - be careful.
Although it's true that- sans GUI- our choices are:
dpkg can be executed from a script without the equivalent of a " -y " switch,
apt requires this to avoid user input. The consequences are that
apt could automatically resolve package dependencies and remove packages other than the target supplied to the command.
Note when I remove iptables (I use firewalld) that lxd and ufw (a front-end for iptables) is also removed. But what if I didn't want lxd removed? Well, it's gone now:
apt-get -y purge iptables Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: iptables* lxd* ubuntu-standard* ufw* 0 upgraded, 0 newly installed, 4 to remove and 54 not upgraded. After this operation, 23.2 MB disk space will be freed. (Reading database ... 90906 files and directories currently installed.) Removing ubuntu-standard (1.417.3) ... Removing ufw (0.36-0ubuntu0.18.04.1) ... Skip stopping firewall: ufw (not enabled) Removing lxd (3.0.3-0ubuntu1~18.04.1) ... Removing lxd dnsmasq configuration Removing iptables (1.6.1-2ubuntu2) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Processing triggers for libc-bin (2.27-3ubuntu1) ... (Reading database ... 90627 files and directories currently installed.) Purging configuration files for ufw (0.36-0ubuntu0.18.04.1) ... Purging configuration files for lxd (3.0.3-0ubuntu1~18.04.1) ... Processing triggers for systemd (237-3ubuntu10.38) ... Processing triggers for rsyslog (8.32.0-1ubuntu4) ... Processing triggers for ureadahead (0.100.0-21) ...
dpkg stops me from potentially altering the system in an unintended way if I were to use it in a scripted execution and refusing to remove both ufw and lxd:
dpkg -r iptables dpkg: dependency problems prevent removal of iptables: lxd depends on iptables. ufw depends on iptables. dpkg: error processing package iptables (--remove): dependency problems - not removing Errors were encountered while processing: iptables
So although it's true we like to ensure our scripts complete successfully and not exit in error, it might be desirable for a script to fail than complete by modifying the system outside of the target of the command. Such a use-case might make
dpkg -r more desirable for scripted execution.