Monday 25 March 2013

Keeping your Raspberry Pi updated with APT

Many Linux distributions including Raspbian for the Raspberry Pi come with the APT (Advanced Package Tool) package manager.

Access to this is often available as a GUI (Graphical User Interface), to help you update, upgrade and install new software packages on your computer. However if you can use APT via the command line you can save yourself a lot of time.

As a reminder to gain access to the command line, if you are logged directly into  the Raspberry Pi, you will need to load Terminal (click LXTerminal on the desktop). Alternatively Remotely logging into the Raspberry Pi via SSH gives you access to the command line.

Update

The first thing is to ensure you are using the latest versions of software. There are two stages to this. First you want to update the list of available software which is stored locally on your machine. You should always do this before starting any type of upgrade. To do this simply type:

sudo apt-get update




To then upgrade any software packages type:

sudo apt-get upgrade




and enter y when asked "Do you want to continue [Y/n]?"

Search

To search for a package that you would like to install type:

sudo apt-cache search packagename

i.e. for chromium




Install

To then install this package:

sudo apt-get install packagename

i.e. for chromium




Before running this command it is often worth running with the flag -s, which simulates the install. This enables you to check that the install is only installing what you expected:

sudo apt-get install -s packagename

i.e. for chromium




Remember to run the command without the -s flag to actually install the package once you have simulated it.

Uninstall

To remove a software package use:

sudo apt-get remove packagename

i.e. for chromium




Again its worth running this with the simulation flag -s first to check everything is as expected:

sudo apt-get remove -s packagename

i.e. for chromium




Kernel Update

Every so often the kernel or core program needs to be updated. This is not updated using the apt-get upgrade command, so you need to specifically tell it to update the kernel. This is done by typing:

sudo apt-get dist-upgrade



Hopefully this has given you a brief  introduction into the APT package manager and how to keep all your software packages up to date using the command line.

4 comments:

  1. Great post. Just wanted to add that a full system upgrade on Arch Linux also updates the Raspberry Pi firmware.
    The command is: sudo pacman -Syu

    ReplyDelete
    Replies
    1. Thanks Ricardo. Great information about the update on Arch Linux. I have only briefly used Arch but fancy having a look into it in more detail. Perhaps it will be the basis for a future blog post...

      Delete
  2. I'd probably recommend people use aptitude, instead of apt-get. Both are great tools, and I don't want to start an apt flamewar, but aptitude has much friendlier commands.

    The biggest benefit is 'aptitude search' vs 'apt-cache search' -- it's the same command you run to install packages, just use the search method instead. Unlike apt-get, which is a completely different command.

    Also, I have some reservations about making the recommendation to run a dist-upgrade. It seems this post is geared more towards beginners (which is great), but it's an abnormal situation where a dist-upgrade needs to happen. However, the more you know the better you are to handle things thrown at you.

    Here's a quick mapping of the commands to their aptitude counterpart from above:

    apt-get update -> aptitude update
    apt-get upgrade -> aptitude upgrade -> aptitude safe-upgrade # **safe-upgrade recommended**[1]
    apt-get install chromium -> aptitude install chromium
    apt-get -s install chromium -> aptitude -s install chromium
    apt-get remove chromium -> aptitude remove chromium
    apt-get -s remove chromium -> aptitude -s remove chromium
    apt-get dist-upgrade -> aptitude full-upgrade

    Cheers!
    -Tim

    [1] The safe-upgrade option in aptitude is a much better alternative than plain-old upgrade, as it makes sure you have all dependencies for the updated packages before trying to install them.

    ReplyDelete
    Replies
    1. Hi Tim,
      Thanks for your comments, I found the aptitude vs. apt commands very interesting, and I am sure others will also. You are right I wrote this to help persuade beginners that the command line is not scary, and really simplifies a lot of tasks. It is difficult to gauge what to include and I felt apt vs. aptitude may confuse matters. I used to think apt was short for aptitude, and thought they were the same thing!
      As for dist-upgrade some have commented that you should only use this, and others that you should not use it! There is a lot of conflicting information out there! I tend to use upgrade initially and when a kernel update is available, I use dist-upgrade. Which is relatively rare, but not that unusual that I felt I should ignore it.
      Thanks again for your comments, it may well be worth me covering this topic in more detail in a later blog!
      Trevor

      Delete