Monday, March 04, 2013

Adding software to the pi.

Last time I looked at adding the no-ip client to the Raspberry pi through downloading source files and compiling software with the make command.

There are a few other ways of getting software onto your device, clearly you can program something yourself, and compile it.

Or you could use the Raspberry pi app store.

Or you could use a package manager called apt-get

Background
The Rasbian distribution of Linux is built on top of a different Linux distribution called Debian.
Debian is cool not only because the distributions, (woody, buzz wheezy etc) are named after toy story characters, but because it's incredibly stable, all software that is released to the apt-get "store" is thoroughly tested.

This means that if you use apt-get to install anything you can practically guarantee that it will work.

This doesn't mean that you can guarantee it will be exploit free however, that guaranteed work comes at a price. that price is a longer delay (whilst testing is happening) until software reaches you.


In the future I plan to build software on my Raspberry pi. so lets make sure that I have gcc installed.

to install gcc I type
sudo apt-get install gcc

and I get the following:
pi@raspberrypi ~ $ sudo apt-get install gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap php5-cli ssl-cert
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  cpp
Suggested packages:
  cpp-doc gcc-multilib autoconf automake1.9 libtool flex bison gcc-doc
The following packages will be upgraded:
  cpp gcc
2 upgraded, 0 newly installed, 0 to remove and 186 not upgraded.
Need to get 21.6 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]?


Obviously I already have gcc installed, but there is an upgrade available.
So I chose to install it by pressing Y

I can choose to install things by using apt-get followed the the word install then the name of the package
I can remove by typing apt-get remove

if you want to remove all traces you can use
sudo apt-get --purge remove

or, (say you've installed apache2 there are a few configuration tools that seem to want to hang around) you can type

sudo apt-get remove apache2*
That removes everything with apache2 in the name


Updating the list of packages
when you've got a lot of software installed on windows knowing if it's all up to date can be a bit of a nightmare, I suppose for the operating system there is windows update.
but what about the copy of apache running, how do I know if my, Oracle server is up to date

On the rasbian OS it's easy, you just type

 sudo apt-get update
and it tell you

If you want to have just one thing upgraded then type
sudo apt-get upgrade gcc

To upgrade everything don't specify a package, just type
sudo apt-get upgrade

and wait whilst the package manager upgrades all the software on your system.

Another way that you can install software is to use dpkg

Packages in the Debian based operating system are all zipped neatly together in .deb files.
If you have downloaded a .deb file you can install it with the following command

sudo dpkg -i /my/path/to/my/file.deb

You can remove software with the same command, but using -r instead of -i

sudo dpkg -r /my/path/to/my/file.deb


What's installed
You may be wondering, what's installed, I mean how do I know to remove something if I don't even know that I have it.

For that we'll use the dpkg utility again.
type:

dpkg -l

This lists loads of installed packages, and they all wizz past too fast to read.
Try typing this instead

dpkg -l | more

Then hit enter to move down 1 line at a time, or space as a page down. (hit q to exit half way through)



Problems
one problem that I have found whilst running apt get is that the following errors have been thrown up

    pi@raspberrypi ~ $ sudo apt-get update
    Err http://archive.raspberrypi.org wheezy InRelease
    
    Err http://archive.raspbian.org wheezy InRelease
    
    Err http://archive.raspberrypi.org wheezy Release.gpg
      Temporary failure resolving 'archive.raspberrypi.org'
    Err http://archive.raspbian.org wheezy Release.gpg
      Temporary failure resolving 'archive.raspbian.org'
    Reading package lists... Done        
    W: Failed to fetch http://archive.raspbian.org/raspbian/dists/wheezy/InRelease

    W: Failed to fetch http://archive.raspberrypi.org/debian/dists/wheezy/InRelease

    W: Failed to fetch http://archive.raspberrypi.org/debian/dists/wheezy/Release.gpg  Temporary failure resolving 'archive.raspberrypi.org'

    W: Failed to fetch http://archive.raspbian.org/raspbian/dists/wheezy/Release.gpg  Temporary failure resolving 'archive.raspbian.org'

    W: Some index files failed to download. They have been ignored, or old ones used instead.

This means that the apt-get utility can't find the package sources,

either the package source is offline, (pretty unlikely)
or you can't find them for another reason.

I found that I couldn't resolve them because the DNS resolution of my home router was a little flakey,

To combat this you need to add a more robust DNS server to your list of DNS servers to try.

so type
sudo nano /etc/resolv.conf

the add the lines
nameserver 8.8.8.8 
nameserver 8.8.4.4

Then exit and save.
(those belong to google, and they have opened them up for public access) -of course you could use your ISPs name servers IP addresses in place of, (or as well as) those google owner server addresses above.








Of course it might be that the server hosting the packages is offline.

 the place where apt-get looks for packages is defined in a text file called sources.list, you can look at this file

pi@raspberrypi ~ $ cat /etc/apt/sources.list
deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

you can browse to http://mirrordirector.raspbian.org/raspbian/ to find out if it's still online using a regular internet browser, (such as internet explorer, or firefox.

Obviously if you can't get to this repository at all, then there is a good chance that your apt-get is failing because the place it's looking for updates just doesn't exist any more.
in which case you should edit the /etc/apt/source.list file to replace the broken repository with one that does work.









No comments: