Free Space on Your Raspberry Pi SD Card


The Raspbian image is available in two sizes from the Official download page. If SD card storage space is an issue it can sometimes be useful to reduce the size of these images. This guide will show how you can remove approximately 1GB of packages that you may not need for your Raspberry Pi project.

SD Card Image Sizes

The main difference between the two images is the inclusion of the desktop environment on the larger version. Using the “lite” image is fine but what if you want the desktop environment but still want to reduce the size of the image?

The “RASPBIAN STRETCH WITH DESKTOP” image is a 1.7GB download that expands to 4.8GB. The “RASPBIAN STRETCH LITE” version is a 350MB download which expands to a 1.8GB image file.

There are a number of large packages that come installed on the full Raspbian image that can be removed to free up space on your SD card.

For details on writing these images to an SD card please see the Write SD Card Images Using Etcher On Windows, Linux and Mac tutorial.

Displaying Current SD Card Usage

To see how much space is being used on your SD card you can run the following command :

df -h

This will give an output like this :

SD Card Space Usage

This shows my SD card is 15GB in size with 4.3GB used.

Finding Packages to Remove

In order to list all the currently installed packages you can use :

dpkg --get-selections

The output is quite long so you might want to export to a text file :

dpkg --get-selections > packages.txt

This text file can be loaded into a text editor if required.

In order to find out which packages are taking up the most space you can use the following command :

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n

This list will be quite long but the packages listed last will be the biggest.

Removing Packages

To remove a package you use the following command :

sudo apt-get purge -y packagename

where “packagename” is the name of the package shown in the dpkg list generated in previous steps.

For example to remove the Wolfram engine you would use :

sudo apt-get purge -y wolfram-engine

Which packages you choose to remove is up to you.

As Reddit user “doc_willis” points out the “-y” option will remove the package with no prompting. You may wish to run the command without this option so you can verify what is going to be removed before committing to removing it.

Here is a table showing the command to remove a specific package and the space you will save by doing so:

Command to Remove PackageSize
sudo apt-get purge -y wolfram-engine680MB
sudo apt-get purge -y libreoffice*245MB
sudo apt-get purge -y oracle-java*160MB
sudo apt-get purge -y scratch2140MB
sudo apt-get purge -y scratch91MB

Removing Wolfram, Libreoffice and Oracle Java can free up to 1GB of space. That’s a useful amount that you can use for other purposes if you don’t need those packages.

Recovering Additional Space

Additional space can be recovered by uninstalling packages that were only installed to support the packages that have now been removed :

sudo apt-get autoremove

Finally you can run the “clean” command to clear out the local repository of retrieved package files :

sudo apt-get clean

Hopefully this guide will be useful in helping you make the most of your SD card capacity.


1 Comment

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.