Element14 Raspberry Pi User manual

Raspberry Pi
User Guide
Getting
started
Operating Systems
& Installation
Learn
the ropes
Linux &
Packages
Making the
most of your Pi
Pi Projects
element14.com
®
Raspberry Pi User Guide.indd 1 08/07/2014 14:43

CONTENTS
Unpack the box 3
Operating Systems 4
Installation 6
Loading the O/S 7
Raspbian 8
Command line: Learn the ropes 10
Packages: How do they work? 16
RaspBMC 20
Camera controller 22
Sending output 26
Minecraft Pi 30
Postscript 32
Raspberry Pi User Guide.indd 2 08/07/2014 14:43

Unpack the box
Inside the box you will find the Raspberry Pi board,
a 5V Power Supply (optional) and a 8GB microSD card.
Depending on which bundle you might have purchased you might
also receive a case or other accessories. Feel free to put those items
together prior to starting up your Pi. The Pi requires 5V 1A power
so if you did not purchase a power supply you will need to locate
one that has a Micro USB tip on the end. Many smartphone and
tablets use Micro USB charging cables, those will work just fine.
Raspberry Pi is a trademark of the Raspberry Pi Foundation. Parts of this manual are reproduced from ‘Raspberry Pi Beyond the Manual’ and
is copyright of or licensed by Future Publishing Limited (a Future plc group company), UK 2013. All rights reserved. The rest of this manual is
copyright of Premier Farnell UK Limited, 2014 and all rights are reserved. No part of this manual may be sold, licensed, transferred, copied
or reproduced in whole or in part in any manner or form or in or on any media without the prior written consent of the copyright owner.
3
Raspberry Pi User Guide.indd 3 08/07/2014 14:43

Operating Systems
Let’s take a look at a sweet selection of
tasty operating systems for the Raspberry Pi.
The Raspberry Pi phenomenon appears to go from
strength to strength; like a runaway train, it’s ploughing
ahead and forging itself a place in the record books.
It’s hardly surprising – the hardware
alone is developed perfectly for the goals
of the Raspberry Pi Foundation, the
pricing is pitched perfectly, and having
the unique versatility of Linux as the
operating system seals the deal nicely.
Most buyers, once they get their hands
on their new RPi, make a move towards
the official Raspberry Pi site and follow the
getting started instructions therein; the
end result is the user running Raspbian
‘Wheezy’, the Foundation’s recommended
operating system, creating, learning and
programming, and strapping the poor wee
beast on to a weather balloon and sending
it to the outer edge of the atmosphere.
What many RPi users don’t realize, though,
is that there’s a wealth of other operating
systems available for their beloved Pi.
We thought, therefore, that those users who
aren’t aware of these other sweet toppings
for the Raspberry Pi need to be informed,
and what’s more, they need to have a
chocolate box selection presented to them.
› OUR SELECTION
■ Raspbian
■ Risc OS
■ Arch
■ RaspBMC
■ OpenELEC
■ Pidora
How we tested...
Therefore, to get a true all-round
perspective, we took the time to install
the operating systems on a fresh 8GB
microSD Card card. The areas we’re
looking at are installation, default
software, media playback (out-of-the-
box), looks and usability, the community
behind the OS and their respective
attitudes toward software freedom.
Basically, the very stuff that makes a Linux
user decide on what system to use.
We also want to gauge this from the point
of view of someone who’s not as familiar
with Linux as other people are, so that
they can jump into the project without too
much hassle, and not end up leaving it
feeling disheartened.
4
Raspberry Pi User Guide.indd 4 08/07/2014 14:44

Raspbian
This is the recommended
distro by the Raspberry
Pi Foundation. Unless
you have good reason
to use a different one, it’s
probably your best bet.
It’s based on Debian Wheezy, so you can easily
install anything from the huge Debian repositories.
The default desktop environment is LXDE,
which is very lightweight, but a little basic for
some tastes. Xfce is available for people who
like a few more graphical niceties. It has the
raspi-config program, which is probably
the easiest way of configuring your Pi.
The Raspberry Pi was designed to get
children into programming, and Raspbian
was designed with this in mind. You’ll find
Idle
(a Python IDE) and
Scratch
(a programming
environment for young children) on the desktop.
It’s available from: www.raspberrypi.org.
Arch Linux
While Raspbian has
been created to try
to shield users from
the internal setup of
the OS, Arch Linux is
designed to help users
understand how the system works.
The initial image, available from
www.raspberrypi.org, includes just the basic
system to get your Pi running and connected
to the network. It doesn’t include much of
the software you may want to use, such as a
graphical environment, for example. You should
find the information you need at bit.ly/9APmgA.
Taking it from this initial state to a working
system will require a bit of work, but along
the way you’ll learn about how the internals
of a Linux distribution fit together.
Whether or not this is worth all the work,
does of course, depend on you.
RaspBMC
The Raspberry Pi may
have been designed
as an educational tool,
but hobbyists have
been pretty quick to
make it a toy. This distro
is designed to turn your Pi into a media center
that can be used to control your TV. It’s based
on XBMC, which allows you to play music and
videos that you have as files, or stream them
from the internet. The image can be downloaded
from: www.raspbmc.com. For details of how to
install it and set it up, see the following pages.
If you have a
MythTV
back-end set up, you can
use XBMCPi to provide a front-end interface.
Depending on what type of media you
want to play, you may need to purchase
the codec packs that provide access to
patent-protected video and audio algorithms.
Risc OS
The difference with the
Risc OS is that it is small
and fast. Developed
when the fastest desktop
computer was an 8MHz
ARM2 with 512KB of
RAM. The core system including windowing system
and a few apps fits inside 6MB. That means it’s fast
and responsive on modern hardware. The memory
taken by apps is usually counted in the kilobytes.
To Risc OS a 700MHz 512MB Raspberry Pi is
luxury, what to do with all that memory? Risc OS like
Raspbian, takes you to a nice GUI at the startup.
One feature of the Risc OS is that it boots to the
desktop in 1080P by default. The Risc desktop
is a little retro but is functional in its default mode.
The Risc OS take a little getting used it, one caveat
is that the Ethernet port is disabled at launch so
it requires some configuration before using.
5
Raspberry Pi User Guide.indd 5 08/07/2014 14:44

Installation
Do you need a PhD to install the OS?
The NOOBS operating system installation is as easy
as copying files onto your SD card.
The installation of an operating system
image is fairly well documented, as per
the area on the Raspberry Pi site titled
Guide for beginners
which can be found
here: goo.gl/53xgp, along with the simple
installation routine of using either ddon
Linux, or with the new NOOBS image you
simply unzip the image download and copy
the files onto a blank formatted microSD
card in Windows. The process is relatively
painless, it’s what happens after you insert
the microSD card into the Raspberry Pi
and apply some power that the fun starts.
The six operating systems on the NOOBS
card – Raspbian, Risc OS, Arch Linux,
OpenELEC, RaspBMC and Pidora – each
have their own nuances, and methods by
which to install and provide the user with
a base working graphical desktop. While
having a GUI isn’t absolutely necessary, it
does cover the large percentage of users
who are new to Linux. That being the case,
the definition of ‘installation’ must include
getting to the point whereby the new user
can recognize the operating system as
they would a standard Linux desktop – in
other words, be presented with a graphical
user interface. In a world where easing
the user into the bath water of Linux is
paramount, Raspbian has the most user
friendly desktop, but the other offerings
have just as good a start for the user.
Risc OS, for example; once transferred
to the SD card and booted, we are rapidly
launched into a colorful and friendly
GUI, with relatively detailed messages
informing us of any issues during the
initial boot and setup. From here, we can
simply click on the ‘Configure’ icon and
begin to alter any settings we see fit.
Arch Linux for the RPi is a different beast,
booting the user into a terminal environment
and leaving them to download, install
and configure their OS. Arch, once fully
appreciated, is one of the best operating
systems available, but it takes some
tweaking to get to a standard desktop.
OpenELEC is the simplest version of XBMC,
starting directly into the XBMC GUI without
any additional configuration required.
RaspBMC makes it easy for you, once
you select this operating system you
are taken directly to the GUI, no scary
terminal prompts to deal with. Once
you have completed the configuration
screens and RaspBMC has checked
for updates, you will be ready to go.
Pidora which is a remix of the Fedora Linux
distribution is fairly easy to configure. Once
you select this O/S, you will be presented
with several configuration screens and then
the desktop will load. One thing to watch
out or here is the terminal commands are
a little different than the other operating
systems (distros in Linux language). The
foundation that compiled Pidora has
a good tutorial here bit.ly/1piC2LA.
In summary, Raspbian would be the easiest
to use and has the most support from
the Raspberry Pi Foundation. OpenELEC
offers the most media support if that is
the route you would like to go. The other
operating systems all have their advantages
and disadvantages. It is up to you to
decide which way you would like to go.
6
Raspberry Pi User Guide.indd 6 08/07/2014 14:44

Loading the O/S
The memory card is affectionately
referred to as NOOBS.
NOOBS is a way to make setting up a RaspberryPi for the first
time much, much easier. You won’t need network access, and
you won’t need to download any special imaging software.
Insert the microSD card in the memory slot
underneath the board. Plug your power
cord into the port next to the HDMI video
port. When you boot up for the first time,
you’ll see a menu prompting you to install
one of several operating systems into
the free space on the card. The choice
means you can boot the Pi with a regular
operating system like Raspbian, or with a
media-center specific OS like RaspBMC.
Once you’ve selected the O/S you’d like
(see the O/S section for more information),
make sure you check the dialogue box
at the bottom of the page for the proper
language that you prefer. The installer will
build the O/S that you selected (a good
time for a sandwich or a cup of coffee).
Once you’ve installed an operating system,
your Pi will boot as normal. However,
NOOBS stays resident on your card, by
holding Shift down during boot you can
return to the recovery interface. This allows
you to switch to a different operating
system, or overwrite a corrupted card with
a fresh install of the current one; it also
provides a handy tool to let you edit the
config.txt configuration file for the currently
installed operating system, and even a
web browser so you can visit the forums
or Google for pointers if you get stuck.
Once the installation is complete your Pi will
restart and a bunch of strange looking text
will appear on your screen. If you are new to
Linux this might take you back to the “DOS”
days. Not to fear this is called the “command
line” You will see at the bottom of the page
the last line reads – raspberrypi login:
Next you will need this information.
Thedefault username and password are:
Username: pi
Password: raspberry
When you hit the enter key you
will see the following line
Pi@raspberrypi ~ $
Type the following to launch the desktop:
startx
Congratulations! You now have started
up your Pi! Now go explore.
■The microSD card
slot is located on
the underside of the
Raspberry Pi board.
7
Raspberry Pi User Guide.indd 7 08/07/2014 14:44

Raspbian
For the majority of people who use it, Raspbian
will be the graphical face of the Raspberry Pi.
It can be obtained and installed on to an SD card by
following the instructions on the previous page.
Once it’s up and running, it’s a good
idea to grab the latest versions of all the
software by connecting your Pi to the
internet, opening a terminal and running:
sudo apt-get update
sudo apt-get upgrade
The killer feature of Raspbian is the
raspi-config
program. This will start
automatically the first time you boot,
or can be run at any time by typing
sudo raspi-config in a terminal.
It has got quite a few options,
but the most important are:
■ expand_rootfs Because of the way
Raspbian is installed, it will only create
a 2GB filesystem, so if you have a
larger card, any remaining space
will remain unused. You can use this
option to expand the filesystem to take
advantage of any wasted space.
■ memory_split The Raspberry Pi uses
the same chunk of memory for both
the main processor and the graphics
chip. Using this option, you can change
the amount allocated to each.
■ overscan This option can be used on
some displays to make the graphics
expand to fill the whole screen. You can
safely ignore it unless you have problems.
■ overclock Get an extra 50 per cent
performance at no extra cost! See
‘Overclocking’ for more details.
■ boot_behaviour This rather
cryptically named option changes
whether your Pi boots into a graphical
environment or a text one.
The installed software has been kept
to a minimum. This is a good idea, but
you may find that tools you use on other
desktop distros aren’t there. Fortunately,
as Raspbian is linked to the Debian Armhf
repositories, you have access to more
software than you’re ever likely to need. If
you like using a mouse, you may want to
install a graphical package manager. We
recommend
Synaptic
. To install it, type:
sudo apt-get install synaptic
in a terminal. It can then be opened by
going to the
‘LXDE menu > Preferences
> Synaptic Package Manager’.
You can
then install any software you want.
■Like all good
distros, Raspbian
comes with a
selection of addictive
time-wasters. This
is Squirrels from the
Pygames selection.
8
Raspberry Pi User Guide.indd 8 08/07/2014 14:44

12 COOL RASPBERRY PI PROJECTS
■ The complete channel one temperature monitor and alarm project
■ The Raspberry Pi softball camera
■ The Raspberry Pi karaoke machine
■ The Drinkmotizer: a Raspberry Pi drink mixing robot
■ New Year’s Eve countdown timer with fireworks launching ability
■ Raspberry Pi remote fish tank controls: AKA Project Goldie
■ The scary door
■ RaspiWatt: discover power consumption using a Kill-A-Watt & Pi
■ Build your own Gertboard experimenter kit
■ Raspberry Pi enabled Christmas lights
■ Ultimate Raspberry Pi bundle security system
■ Pumpkin Pi project for Halloween and a second helping of pumpkin Pi
www.element14.com/raspberrypiprojects
12 COOL RASPBERRY PI PROJECTS
The complete channel one temperature monitor and alarm project
The Drinkmotizer: a Raspberry Pi drink mixing robot
New Year’s Eve countdown timer with fireworks launching ability
Raspberry Pi remote fish tank controls: AKA Project Goldie
RaspiWatt: discover power consumption using a Kill-A-Watt & Pi
Build your own Gertboard experimenter kit
Raspberry Pi enabled Christmas lights
Ultimate Raspberry Pi bundle security system
Pumpkin Pi project for Halloween and a second helping of pumpkin Pi
www.element14.com/raspberrypiprojects
Overclocking
The processor at the heart of the Raspberry
Pi is designed to run at 700MHz. That
is, perform 700,000,000 operations
per second. Of course, ‘designed to
run’ doesn’t mean ‘has to run’. You can
increase this speed. However, doing this
will increase the power consumption,
which in turn increases the amount of
heat generated. If it gets too hot, you’re
liable to have a smoking pile of silicon
rather than a functional processor.
Fortunately, Raspbian includes a tool to
help you ramp up the speed while also
keeping a careful eye on the temperature.
And because this is an official tool,
using it won’t void your warranty (unlike
earlier unofficial methods). Overclocking
your Raspberry Pi is simply a matter
of running sudo raspi-config and
then selecting ‘Overclocking’.
There are a few options to choose from,
depending on how brave you’re feeling.
Ifyou find that your Pi becomes unstable,
reboot with the Shift key held down to
disable overclocking, then change the
option in
raspi-config
. The maximum
setting should give you a whopping 50
per cent extra speed, which we found
makes a real difference to the desktop user
experience, especially for web browsing.
If you want to keep an eye on your
core temperature, you can add the
Temperature widget to the LXDE panel.
However, your Pi will automatically turn
off overclocking once it reaches85°C.
■Overclocking will
increase the amount
of power that your Pi
draws, and so may
become less stable if
running a number of
USB devices.
9
Raspberry Pi User Guide.indd 9 08/07/2014 14:44

Command line:
Learn the ropes
Get to grips with your Raspberry Pi’s
command line interface and unleash its
full power without using themouse.
As you have no doubt discovered, Raspbian has a graphical
interface similar to that of Windows or Mac OS X.
You can do most of your day-to-day
tasks in this interface. There’s a file
manager, web browser, text editor and
many other useful applications. However,
sometimes you need an interface that’s a
bit more powerful, and this is where the
command line interface (CLI) comes in.
It’s also known as the terminal or shell.
This is an entirely text-based interface,
where you type in commands and
get a response. We won’t lie to you:
it will seem confusing at first. Don’t
worry, though – once you’ve had a bit
of practice, it will start to make sense,
and spending a little time learning it
now will pay dividends in the future.
■LXTerminal running
on the Raspbian
desktop.
10
Raspberry Pi User Guide.indd 10 08/07/2014 14:44

The first thing you need to do is open up a terminal.
Clickon‘LXTerminal’ on the Raspbian desktop.
You should now see a line that looks like:
pi@raspberrypi ~ $
This is the command prompt. Whenever
you see this, you know the system is
ready to receive input. Now type pwd,
and press Enter. You should see:
/home/pi
If you’ve changed your username, then
you’ll see a different line. The rather
cryptically named pwd command stands
for Print Working Directory, and the
system simply outputs the directory you’re
currently in. When you start a terminal,
it will go to your home directory.
Now we know where we are, the next
logical thing to do is move about through
the directories. This is done using the cd
(change directory) command. Try entering:
cd ..
pwd
You should find that the system returns
/home. This is because we’ve cded to
‘..’ and two dots always points to the
parent directory. To move back to your
home directory, you can enter cd pi.
There is also another way you can do
it. The ~(pronounced tilda) character
always points to your home directory, so
wherever you are in the filesystem, you
can enter cd ~ and you’ll move home.
Now type ls and hit Enter. This will list
all the files in the current directory. One of
the big advantages of commands is that
we can tell them exactly how we want
them to behave. This is done using flags,
which come after the command and
start with a ‘-’. For example, if we want
to list all the files in the current directory
(including hidden ones, which start with a
‘.’ on Unix-based systems), we use the
flag -a. So, in your terminal, type ls -a.
This time, you should see more files
appear. Another flag for ls is -l. This
gives us more information about each file.
Try it out now by typing ls -l. You can
even combine flags, such as in ls -al.
Interactive programs
Most of the commands we’re dealing with
here are non-interactive. That means you
set them running and then wait for them
to finish. However, not all command line
programs work like this. For example, when
you first booted Raspbian, it started a config
tool that ran in the terminal. There are a few
other programs that work in a similar way.
Traditionally, the most common has been
text editors that allow you to work on files
if you don’t have a graphical connection.
There are a few quite complicated ones that
are great if you spend a lot of time working
from the command line, but they can be
hard to learn. There’s also an easy-to-use
terminal-based text editor called nano.
Enter nano followed by a filename at the
command prompt to start it. You can then
navigate around the text file and make any
changes you need. Press Ctrl+X to save
your work and exit back to the prompt.
11
Raspberry Pi User Guide.indd 11 08/07/2014 14:44

K nowing what commands to use
At this point, you’re probably wondering how on earth
you are supposed to know what commands
and what flags you can use for a task.
Well, there’s good news and bad news.
The good news is that it’s usually not too
difficult to find out the flags for a command.
Most commands support the -h or --help
flags, which should give some information
about what flags a command can take
and how to use it. For example, if you
run ls --help, you’ll see a long list of
flags and what they all do, including:
-a, --all do not ignore
entries starting with .
…
-l use a long listing format
The second way of finding information on
a command is using man. This is short for
manual. It takes a single argument, that is, a
word after the command that isn’t preceded
by a hyphen. It then displays information on
the command given as an argument. Tosee
the man page for ls, type man ls. You can
navigate through the page using the up
and down arrows, or the page up and page
down keys to scroll faster. To search for a
word or phrase inside the man page, type
/, then the phrase. For example, /-l will
find all occurrences of -l. You can use the
Nkey and Shift+N to scroll forwards and
backwards through the occurrences of-l.
As we introduce more commands, it’s
good to take a look at the help and the
man page to familiarize yourself with
what they do. Of course, you can always
Google a command if you find the text-
based help a little off-putting, but staying
in the terminal will help you become more
familiar with the command line interface.
Tab completion
When you’re dealing with
long filenames, it can be very
annoying to have to type them
out every time you want to run
a command on them. To make
life a bit easier, the terminal uses
tab completion. This means that
if you start typing a filename
and press the Tab key, the
system will try to fill in the rest
of the name. If there’s only one
file that fits what you’ve typed
so far, it will fill in the rest of the
name for you (try typing cd /h
then pressing Tab). If there are
more than one, it will fill in as far
as the two are the same, If you
press Tab again, it will show
the options (try typing cd /m,
and then pressing Tab twice).
■You can even watch movies in the command line. To stream the classic,
just enter telnet towel.blinkenlights.nl and put somepopcorn on.
12
Raspberry Pi User Guide.indd 12 08/07/2014 14:44

How will I know?
Remember we said there’s good news and bad news?
Well, the bad news is that it can be quite tricky to find
commands if you don’t know what they’re called.
One helpful feature is the man keyword
search. This is done with the -k flag.
To search for all the programs related
to ‘browser’ on your system, run
man -k browser. You’ll notice that
this lists graphical programs as well as
command line ones. This is because there’s
no real difference between the two. You
can launch windows from the terminal,
and sometimes even control them.
If you’ve got
Iceweasel
(a rebranded
version of
Firefox
) installed on your
Pi (it’s not on there by default), you
can open TuxRadar.com in a new
tab in a currently running
Iceweasel
window with the command iceweasel
--new-tab www.tuxradar.com.
We’re now going to quickly introduce a few
useful commands. rm deletes (ReMoves)
a file. mkdir makes a new directory. cp
copies a file from one place to another.
This one takes two arguments, the original
file and the new file. cat outputs the
contents of one or more text files. This
takes as many arguments as you want,
each one a text file, and simply spits their
contents out on to the terminal. less is
a more friendly way of viewing text files.
It lets you scroll up and down using the
arrow keys. To exit the program back to
the command line, press Q. We’ll use all
these commands in examples below, so
we won’t dwell on them for too long.
■Probably the most important command in any Unix-like system is man, since it is the key to
understanding every other command. Take time to become familiar with the structure and language
used and it will make life easier in the future.
find
find is a useful
command for
finding files on your
computer. You use
it in the format find
location flags.
For example, to
find every file on
your computer
that’s changed in
the last day, run
find / -mtime 1
There are more
details of what
this means, and
the different flags
that can be used
over the page.
13
Raspberry Pi User Guide.indd 13 08/07/2014 14:44

Po w er up
So far you’re probably thinking to yourself, “I could have done all this in the graphical
interface without having to remember obscure commands and flags.”
You’d be right, but that’s because we haven’t introduced
the more powerful features yet. The first of them are
wildcards. These are characters that you can put in that
match different characters. This sounds a bit confusing,
so we’re going to introduce it with some examples.
First, we’ll create a new directory, move into it and create
a few empty files (we use the command touch, which
creates an empty file with the name of each argument).
Hint – you can use tab completion to avoid having
to retype long names, such as in the second line.
mkdir wildcards
cd wildcards
touch one two three four
touch one.txt two.txt three.txt four.txt
Then run ls to see which files are in the
new directory. You should see eight.
The first wildcard we’ll use is *. This matches any string
of zero or more characters. In its most basic usage,
it’ll match every file in the directory. Try running:
ls *
This isn’t particularly useful, but we can put it in
the middle of other characters. What do you think
*.txt will match? Have a think, then run:
ls *.txt
to see if you are right.
How about one*? Again, run
ls one*
to see if you were correct. The wildcards can be
used with any command line programs. They’re
particularly useful for sorting files. To copy all the
.txt files into a new directory, you could run:
mkdir text-files
cp *.txt text-files
We can then check they made it there correctly with:
ls text-files/
The second wildcard we’ll look at is ?. This matches
any single character. What do you think:
ls ???
will match? Have a guess, then
run it to see if you’reright.
We can also create our own wildcards to
match just the characters we want. [abc] will
match just a lower-case A, B and C. What do
you think ls [ot]* will match? Now try
ls [!ot]*
What difference did the exclamation mark
make? It should have returned everything that
didn’t start with a lower-case letter O or T.
sudo
When using the Raspberry Pi for normal use,
you can work with files in your home directory
(for example, /home/pi). You will also be able
to view most other files on the system, but you
won’t be able to change them. You also won’t
be able to install software. This is because Linux
has a permissions system that prevents ordinary
users from changing system-wide settings. This is
great for preventing you from accidentally breaking
your settings. However, there are times when
you need to do this. You can use sudo to run a
command as the super user (sometimes called
root), which can do pretty much anything on the
system. To use it, prefix the command with sudo.
For example:
sudo apt-get install synaptic
will install the package synaptic and make it
available to all users.
14
Raspberry Pi User Guide.indd 14 08/07/2014 14:44

Pipes and redirection
The commands that we’ve been looking at so far have all
sent their output to be displayed in the terminal.
Most of the time this is what we want, but
sometimes it’s useful to do other things with
it. In Linux, you can do two other things with
a command: send it to a file, or send it to
another program. To send it to a file, use the
>character followed by the filename. Run:
ls > files
cat files
and you should see that it creates
a new file called files, which
contains the output of ls.
The second option, sending it to another
program, is another of the really powerful
features of the Linux command line,
because it allows you to chain a series of
commands together to make one super
command. There are a lot of commands
that work with text that are designed to
be used in this way. They’re beyond the
scope of this tutorial, but as you continue to
use the command line, you’ll come across
them and start to see how they can be
linked together. We’ll take a look at a simple
example. If you run find / (don’t do it just
yet!) it will list every file on the system.
This will produce a reel of filenames that
will quickly go off the screen. However,
rather than direct it to the screen, we can
send (or ‘pipe’) it to another command
that makes the output easier to read.
We can use the less command that we
looked at on page 13 for this. Run:
find / | less
■Use the sudo command to switch between the normal user ‘pi’, and the superuser ‘root’.
Take it further
We’ve only been able to touch
on the basics of using the
command line, but you should
have enough knowledge
now to get started, and
hopefully you’re beginning
to see just how powerful the
command line interface is
once you get to know it.
If you want to know more (and
you should!) there are loads of
resources in print and online.
LinuxCommand.org is a great
place to start. Its book (
The
Linux Command Line
) is available
from bookshops, or for free
online www.linuxcommand.org/
lc3_learning_the_shell.php.
15
Raspberry Pi User Guide.indd 15 08/07/2014 14:44

Packages:
How do they work?
Discover how Raspbian’s package manager,
apt-get, gets software from online repositories
andmanages it on your system.
If you’re used to Windows, you may be used to each bit of
software having its own installer, which gets the appropriate
files and puts them in the appropriate places.
Linux doesn’t work in the same way (at least,
it doesn’t usually). Instead, there is a part of
the operating system called the package
manager. This is responsible for getting
and managing any software you need. It
links to a repository of software so it can
download all the files for you. Since Linux
is built on open source software, almost
everything you will need is in the repositories
and free. You don’t need to worry about
finding the install files, or anything like that
– the package manager does it all for you.
There are a few different package
managers available for Linux, but the one
used by Raspbian is apt-get. Arch uses
a different one, so if you want to try this
distribution on your Raspberry Pi, you’ll
need to familiarize yourself with the pacman
software, which we won’t cover here.
Before we get started, we should mention
that since this grabs software from the online
repositories, you will need to connect your Pi
to the internet before following this section.
16
Raspberry Pi User Guide.indd 16 08/07/2014 14:44

apt-get is a command line program, so to start with
you’ll need to open a terminal (see the command line
interface section on page 10 for more information on
this). Since package management affects the whole
system, all the commands need to be run with sudo.
The first thing you need to do is make sure you have
the latest list of software available to you. Run:
sudo apt-get update
Since all the software is handled through the
package manager, it can update all the software
for you so you don’t need to bother doing it for
each program separately. To get the latest versions
of all the software on your system, run:
sudo apt-get upgrade
This may take a little while, because open source
software tends to be updated quite regularly. In Linux
terms, you don’t install particular applications, but
packages. These are bundles of files. Usually, each one
represents an application, but not always. For example,
a package could be documentation, or a plug-in, or
some data for a game. In actual fact, a package is just
a collection of files that can contain anything at all.
In order to install software with apt-get, you
need to know the package name. Usually this
is pretty obvious, but it needs to be exactly right
for the system to get the right package. If you’re
unsure, you can use apt-cache to search through
the list of available packages. Tryrunning:
apt-cache search iceweasel
This will spit out a long list of packages that all
have something to do with the web browser
(
Iceweasel
is a rebranded version of
Firefox
).
To install
Iceweasel
, run:
sudo apt-get install iceweasel
You will notice that apt-get then prompts you
to install a number of other packages. These are
dependencies. That means that
Iceweasel
needs the
files in these packages in order to run properly. Usually
you don’t need to worry about these – just press Y
and the package manager will do everything for you.
However, if your SD card is running low on space, you
may sometimes come across a program that has so
many dependencies that they’ll overfill the device. In
these cases, you’ll either need to free up some space or
find another application that has fewer dependencies.
■apt-cache in a terminal will give you a list of available packages.
17
Raspberry Pi User Guide.indd 17 08/07/2014 14:44

If you then want to remove
Iceweasel
, you can do it with:
sudo apt-get purge iceweasel
The package manager will try to
remove any dependencies that
aren’t used by other packages.
You’ll often see packages with -dev at
the end of package names. These are
only needed if you’re compiling software.
Usually you can just ignore these.
apt-get is a great tool, but it isn’t as
user-friendly as it could be. There are
a couple of graphical tools that make
package management a bit easier. The
first we’ll look at is
Synaptic
. This isn’t
installed by default on Raspbian, so you’ll
have to get it using apt-get with:
sudo apt-get synaptic
This works with packages in the
same way as apt-get, but with a
graphical interface. Once the package
is installed, you can start it with:
--where is synaptic
See below for more information.
The second graphical tool is the Raspberry
Pi App store. Unlike apt-get and
Synaptic
, this deals with commercial
software as well as free software, so
you have to pay to install some things.
It comes by default on Raspbian, and
you can get it by clicking on the icon on
desktop. See ‘Raspberry PiStore’ on
the next page for more information.
■
Synaptic
provides a user-friendly
front-end to the apt package
management system.
Synaptic
Synaptic
lets you do everything
you can with the command
line apt-get, but the graphical
interface is easier to use. We
find it especially useful when
searching, because the window
is easier to look through
than text on the terminal.
18
Raspberry Pi User Guide.indd 18 08/07/2014 14:44

Compiling software
Sometimes, you’ll find you need software that isn’t in the repository, and
so you can’t get it using apt-get. In this case, you’ll need to compile it.
Different projects package their source code
in different ways, but usually, the following
will work. Get the source code from the
project’s website, and unzip it. Usually,
the filename will end in .tar.gz or .tgz. If
this is the case, you can unzip itwith:
tar zxvf <filename>
If the filename ends in .tar.bzip2, you need
to replace zxvf with xjf. This should
now create a new directory which you
need to cd into. Hopefully, there’ll be a
file called INSTALL, which you can read
with less INSTALL This should tell you
how to continue with the installation.
Usually (but not always), it will say:
./configure
make
sudo make install
The first line will check you have all the
necessary dependencies on your system.
If it fails, you need to make sure you have
the relevant -dev packages installed.
If that all works, you should have the
software installed and ready to run.
■The Pi Store is an app store
foryour Raspberry Pi.
Raspberr y Pi store
The Raspberry Pi store allows
users to rate the software, so you
can see how useful other people
have found it. It also includes
some non-free software. However,
it doesn’t have anywhere near
the range that is available
through apt-get or
Synaptic
.
19
Raspberry Pi User Guide.indd 19 08/07/2014 14:44

RaspBMC
You can install a media player, such as VLC,
on to Raspbian, and use that to play videos.
This works fine if you’re using your Raspberry Pi as a general
computer and giving it occasional multimedia functions.
However, the small size of the hardware, and
the fact that it runs silently, makes it a good
choice for building your own entertainment
center. You could start from Raspbian and
customize it to your needs, and this is a
good idea if you have any unusual functions
in mind. Fortunately for us (and you), a team
of hackers have done all the difficult bits of
building a media center for the Raspberry
Pi, and packaged it for you to use. Follow
the guide on page 6 to install the RaspBMC
operating system from the NOOBS image.
This uses the popular XBMC media desktop,
which is quite different from LXDE, which
you may have experienced on Raspbian.
You can play media stored locally or, through
the use of add-ons, stream content from the
internet. Music and videos can be added
to your setup either by attaching a USB
device, or directly on to the SD card using
FTP (username pi, password raspberry).
See below for how to find the IP address.
Perhaps the only piece of configuration
you will need is to make sure the sound is
sent to the right place. Under
‘System >
System > Audio Output’,
make sure that
Output is set to Analog if you’re using
the jack, or HDMI if you’re using this.
■The Model B+
boards have mounting
holes to help you keep
your entertainment
center tidied away.
20
Raspberry Pi User Guide.indd 20 08/07/2014 14:44
Table of contents
Other Element14 Motherboard manuals