Keeping Your Raspberry Pi Fresh

Keeping Your Raspberry Pi Fresh

In order to keep your Raspberry Pi secure, and to get updated functionality, you should get the firmware and the software updated. This post will describe how to keep your Raspberry Pi updated, as well as how to manage the software for the system. 

Updating the Firmware

As described in Getting Sound and Video to Work on Raspberry Pi, the rpi-update tool should be downloaded from Hexxah's Github, copied to /usr/local/bin/, and made executable.

  • Install software needed to perform the update:
    • pi@raspberrypi:~$ sudo apt-get install ca-certificates git-core binutils
  • Download the script:
    • pi@raspberrypi:~$ sudo wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update
  • Copy the script to /usr/local/bin:
    • pi@raspberrypi:~$ sudo cp rpi-update /usr/local/bin/rpi-update
  • Make the script executable:
    • pi@raspberrypi:~$ sudo chmod +x /usr/local/bin/rpi-update
  • Run the script:
    • pi@raspberrypi:~$ sudo rpi-update
    • In the future to check for updates, just execute this last step!

Every time you want to check for firmware updates, then execute:

pi@raspberrypi:~$ sudo rpi-update

Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS
Performing self-update
Autodetecting memory split
Using ARM/GPU memory split of 192MB/64MB
Updating firmware (this will take a few minutes)
Checking out files: 100% (21/21), done.
Using SoftFP libraries
If no errors appeared, your firmware was successfully updated
A reboot is needed to activate the new firmware

If you have firmware that is already updated, then the output will look like this:

Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS
Performing self-update
Autodetecting memory split
Using ARM/GPU memory split of 192MB/64MB
Updating firmware (this will take a few minutes)
Your firmware is already up to date

Checking Your Firmware Version

If you haven't updated recently, then your output might be something like this:

pi@raspberrypi:~$ /opt/vc/bin/vcgencmd version
Jun 22 2012 19:43:47
Copyright (c) 2012 Broadcom
version 321258 (release)

Today. I ran sudo rpi-update again, and sudo reboot and found that the Raspberry Pi firmware has been updated as recently as June 22, 2012. The update shown to the version did not appear until after I rebooted:

pi@raspberrypi:~$ /opt/vc/bin/vcgencmd version
Jul  1 2012 12:48:16 
Copyright (c) 2012 Broadcom
version 323014 (release)

Updating Software Packages

As I described in Slicing into the Raspberry Pi, the first thing to do after going through the initial boot and reboot is to update the software for the system:

  • Check for updates: 
    • pi@raspberrypi: ~$ sudo apt-get update 
  • Apply updates: 
    • pi@raspberrypi: ~$ sudo apt-get upgrade

Updating Software Releases

At the time of this writing, Debian is on the Squeeze release for it's stable packages. If you stay on this stable release, then the only updated software that you will be able to get will be software updated for security reasons, and not for added functionality. The most current, but unstable release is always known as Sid. When the current Sid is eventually released it will be called Wheezy. The unstable release always stays with the name Sid. 

If you want to get the most updated, and possibly face broken packages from time to time, then you can edit with sudo nano /etc/apt/sources.list and replace squeeze with sidHere is an example of my updated /etc/apt/sources.list. Notice the original lines that referred to squeeze have been commented out, and lines added where squeeze has been replaced with sid:

pi@raspberrypi:~$ cat /etc/apt/sources.list
# deb http://ftp.uk.debian.org/debian/ squeeze main
# deb http://ftp.uk.debian.org/debian/ squeeze main non-free
deb http://ftp.uk.debian.org/debian/ sid main
deb http://ftp.uk.debian.org/debian/ sid main non-free

# Nokia Qt5 development
deb http://archive.qmh-project.org/rpi/debian/ unstable main

After updating the sources.list file, perform the following to update your release:

pi@raspberrypi:~$ apt-get update && apt-get dist-upgrade

Before you try this, be sure you expand your SD card image, as described in A bigger slice of Raspberry Pi. You might also have to do apt-get -f install to finish the upgrade.

Listing Installed Debian Packages

pi@raspberrypi:~$ dpkg -l

or to be to page through the listing use:
pi@raspberrypi:~$ dpkg -l | less
pi@raspberrypi:~$ dpkg -l | more

or to send it to a file:
pi@raspberrypi:~$ dpkg -l > ~/dpkg.list

Listing the Contents of a Debian Package

If you know the name of a package, then you can list the files it contains by using dpkg -L package.

pi@raspberrypi:~$ dpkg -L python

Showing the Information about a Debian Package

To display status information about a package use: dpkg -s package.

pi@raspberrypi:~$ dpkg -s python

Package: python
Status: install ok installed
Priority: standard
Section: python
Installed-Size: 655
Maintainer: Matthias Klose
Architecture: all
Source: python-defaults
Version: 2.7.3~rc2-1
Replaces: python-dev (<< 2.6.5-2)
Provides: python-ctypes, python-email, python-importlib, python-profiler, python-wsgiref
Depends: python2.7 (>= 2.7.3~rc2-1~), python-minimal (= 2.7.3~rc2-1)
Suggests: python-doc (= 2.7.3~rc2-1), python-tk (= 2.7.3~rc2-1)
Breaks: python-bz2 (<< 1.1-8), python-csv (<< 1.0-4), python-email (<< 2.5.5-3), update-manager-core (<< 0.200.5-2)
Conflicts: python-central (<< 0.5.5)
Description: interactive high-level object-oriented language (default version)
 Python, the high-level, interactive object oriented language,
 includes an extensive class library with lots of goodies for
 network programming, system administration, sounds and graphics.
 This package is a dependency package, which depends on Debian's default
 Python version (currently v2.7).
Homepage: http://www.python.org/

Searching for Debian Software

In order to have the most recent results, be sure to follow the previous steps to Update Software Packages. If you want to install software, but are not sure which package name to use, then try apt-cache search keyword. For example I wanted to install Python 3, so I used the following. What is listed, is just a partial listing of the packages found, and I have omitted all the listings after the actual one that is needed to install Python 3. If you are logged in directly on terminal without scroll back, then you may want to pipe the output or more, or less, or redirect the output to a file:

pi@raspberrypi:~$ apt-cache search python3
pi@raspberrypi:~$ apt-cache search python3 | less # allows scrolling back and forth results hide on q
pi@raspberrypi:~$ apt-cache search python3 | more # allows scrolling forward only results seen on q
pi@raspberrypi:~$ apt-cache search python3 > python3.search # file can be viewed for results

python-apipkg - namespace control and lazy-import mechanism for Python
python3-authres - RFC 5451 Authentication Results Header manipulation for Python3
diveintopython3 - Book for learning Python 3
ipython3 - enhanced interactive Python 3 shell
python3 - interactive high-level object-oriented language (default python3 version)

Installing Debian Software Packages

Once you know the name of the Debian software package, then using sudo apt-get install package... is used to install one of more software packages. For example, in order to install python3 and diveintopython3 I used:

pi@raspberrypi:~$ sudo apt-get install python3 diveintopython3

Don't walk away too quickly, as you need to confirm by pressing Enter sometimes. When apt-get it needs to install other packages as dependencies, it will require confirmation. Another reason to watch the output is it will show the extra packages that are installed as dependencies, suggested packages, and recommended packages:

The following extra packages will be installed:
  libexpat1-dev libpython3.2 libssl-dev libssl-doc python-pkg-resources python-setuptools python3-dev python3-pkg-resources python3-setuptools python3.2-dev
Suggested packages:
  python-distribute python-distribute-doc
Recommended packages:

Removing Debian Software Packages

If you have installed packages, and you realize that they are either defective (audacious), or using space you don't want for something that doesn't work that well (totem). Then, using apt-get remove package... will remove the packages that you specify, and any packages that depend upon it. Packages that were installed as dependencies, however, are not removed when this is done. If this occurs, then apt-get will suggest using apt-get autoremove. When I wanted to remove totem, I used:

pi@raspberrypi:~$ sudo apt-get remove python3

The following packages were automatically installed and are no longer required:
  libexpat1-dev libpython3.2 libssl-dev libssl-doc python3.2-dev zlib1g-dev
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  python3 python3-dev python3-pkg-resources python3-setuptools

Do you want to continue [Y/n]? 

The partial output of the command above shows that python3 and packages that depend it on will be removed. However, the packages that were shown as "packages were automatically installed and are no longer required" will not be removed unless apt-get autoremove is used to remove them.

So, to complete the process, I would have used the following. However, since I didn't really get rid of Python 3, I didn't need to do it. There is a really fun Easter Egg to check out in Python 3!

pi@raspberrypi:~$ apt-get autoremove.


Benjamin Hill said...

Hello! Great post. I was trying to write up something similar.

Fast q: I tried using your line
"deb http://ftp.uk.debian.org/debian/ sid main"
on my pi, but it complained about duplicates.

My only line before I tried it was the default
deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

Is this compatible? Can I just add "sid" to my existing line?

micfiz said...

very good information. I am about to install the camera into the RPi from Adafruit. This topic of firmware version updating and such is very useful and a core skill in this endeavor.
Thanks for the contribution to the internet of things.

About Me - WrightRocket

My photo

I've worked with computers for over 30 years, programming, administering, using and building them from scratch.

I'm an instructor for technical computer courses, an editor and developer of training manuals, and an Android developer.