How to uninstall programs on a Raspberry Pi ?

I do a lot of tests on Raspberry Pi that make me install a lot of applications, but I don’t necessarily clean up when finished 🙂

So how to uninstall programs on Raspberry Pi when you need to realize certain projects?
You can uninstall programs on a Raspberry Pi using the package manager or using apt-get. If you uninstall because you lack of disk space, you can also make room on your SD card using other methods

I will show you :
How to get a list of currently installed packages
How to uninstall applications from your Raspberry Pi
– More generally, how to gain more space on your SD card

List of installed programs on Raspberry Pi

Package Manager

Current status of your SD card

The first question that you ask yourself is probably how to find the used space on your sd card
For this, the quickest way is to go to Accessories> File Manager, and right-click on the “/” folder (at the very top) and then Properties
This tool will show you all the space used by your files in order for you to see the remaining space

List installed packages

By default, the only way to find the installed packages graphically is to go to the package manager: Preferences> Add / Remove Software

The tool displays installed programs with a checked box, so you can easily find them and uninstall them if needed

This method is not perfect
There is no way to get the list of all installed packages in one page
You will have to enter each category and scroll through the list to find the checked lines
And this is the main reason why beginners on Raspberry Pi, or at least those who are not familiar with Linux commands, have trouble to remove packages

The good news is that you can see in the bottom right corner the package size

What you can also do is going to Options> Packages logs, and see the latest changes made to the packages.
It looks like this:

This screen will allow you to see the latest packages installed, and generally, find which ones you can remove quickly

If you want to go through the GUI, know that it is possible to install Synaptic, which is a similar tool, but it allows making more advanced filters, like listing only the installed packages
You can find Synaptic in the Add/Remove Software tool
Then start Synaptic, click Status> Installed in the left menu, and you will get the list of installed packages

But the easiest way to list installed packages is really to go through the command line. I’ll explain to you how

Command line

If you manage to remember these few commands, using a terminal is the fastest way to find the packages installed on your Raspberry

Disk usage :

First thing, if you want to see the disk space used in a terminal or ssh, use the df command like this:

$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        28G  4.8G   22G  19% /

The -h option will display values in a human-readable format

List installed packages :

To list every package installed on your Raspberry Pi you can use :

dpkg -l

This command will list all packages, with this format :

The df command doesn’t directly display the space used by each program, but to find the most significant packages you can do something like this :

$ dpkg-query -W -f='${Installed-Size;8}  ${Package}\n' | sort -nr | head -10
  688414  wolfram-engine
  171382  chromium-browser
  168481  oracle-java8-jdk
  143795  scratch2
  114332  raspberrypi-kernel
  110694  libgl1-mesa-dri
   84603  libreoffice-core
   83391  libreoffice-common
   49227  quake3-demo-data
   47627  gnome-user-guide

This command will get the size of each package, and sort it by size
You can replace the last -10 option to get more results

Uninstall programs on a Raspberry Pi

Well, now that I know how many space I have left on my Raspberry Pi and which packages use the most space, how do I remove them?
Let’s take a look at this. It’s not the most complicated

Package Manager

In graphics mode, the search is not very convenient, but the removal of a package is quite simple

Once you have found the package to delete, uncheck the box, click the Apply button at the bottom and confirm

The package will be uninstalled immediately

Command line

Most of the time, you can use apt-get to remove the package via the terminal

For example, I see that I forgot to remove a quake3 package from the last tutorial, I can do it with a :

sudo apt-get remove quake3-demo-data

And that’s it, package deleted and disk space released 🙂

Free more space on Raspberry Pi

Temporary files

In theory, temporary files are temporary 🙂
This means they are automatically deleted when you restart your Raspberry Pi
But if you can not reboot it or you’re stuck, you can empty the folder with one of these commands:

  1. Remove only old temporary files :
    sudo find /tmp -type f -atime +10 -delete
  2. Clear all temporary files (can corrupt some running apps) :
    sudo rm -rf /tmp/*

 

Cache

The apt tool caches a large part of the information used, to avoid downloading everything each time.
Clearing this cache may allow you to unlock a stuck Raspberry Pi due to the lack of disk space
Simply execute this command:

sudo apt-get clean

But remember that the cache will come back after the next update, so it’s a very temporary solution

As long as we talk about the cache, if you surf on the internet with your Raspberry Pi, remember to clear the browser’s cache too.
I’ll bet that you will gain some valuable MB
On any browser, you have to go to Options to clear the cache

Remove unused packages

When you uninstall packages, dependencies often do not automatically uninstall, so you can force them to uninstall in this way:

sudo apt-get autoremove

But the most effective way to free up space, if you do not use these tools is to uninstall wolfram-engine and LibreOffice
This tip will allow you to gain about 1GB of disk space in 10s
Make these commands :

sudo apt-get remove --purge wolfram-engine libreoffice*
sudo apt-get autoremove

free space

Yes, I do!

Find other big folders and files

Ok so you have a disk space problem
We saw how to remove packages or clear the different caches, but this is not necessarily the most considerable part of your used disk space

If you have a huge log file or hundreds of photos/videos stored on your SD card, you’ll have to deal with it before, but how do you find them?
Let’s see how

Graphical way :

“Gnome utility” is a great tool that you can use (the package name is baobab)
You can find it in the Add/Remove software tool, search for “baobab”
It will graphically show you exactly how many free space you have left  and which folder is taking a lot of space:

Thanks to this, it will be much easier to find a file that you would have missed

Command line :

In a terminal, you can do something similar
du is a default supplied command in the Raspberry Pi.
It will list the size of the files and folders of the disk

With some additional options we will get the same result as the graphical tool :

  1. You can see size taken by each subfolder like this :
    sudo du -h --max-depth=1 /
  2. And you can also find the biggest files on the disk like this :
    sudo du -ak | sort -nr | head -50

    You can change the -50 options to get more or fewer files in the list
    Don’t pay attention to access errors when running the command

Conclusion :

You have now learned how to uninstall packages on your Raspberry Pi, and also some tips to free space on your SD card

And of course, if you have a lot of issues with your SD card, that might mean that it is too small and you will have to think about changing it.
It does not cost much nowadays and you will be relieved

 

Leave a Comment