Tuesday, 15 January 2008

apt-get

Installing software is a piece of cake in Ubuntu. For applications, you can just open Add/Remove Applications, select what you want to install and then click on a few buttons to install it. Couldn't be simpler.

For more complex things, you can use Synaptic (or Adept in Kubuntu). This allows you to search through the packages using search tools which make it easy to narrow down the choices to what you want. Synaptic doesn't just give you a list of applications, it gives you absolutely every single utility available in the repositories, making it an extremely powerful tool. Many things are available from there that you wouldn't be able to get using Add/Remove. For instance, you can use Synaptic to install the Kubuntu desktop in an Ubuntu install.

However, both Add/Remove Applications and Synaptic are just graphical front-ends to make it easy for new users to get started. The real work is done by apt-get, which you can access yourself from the command line if you wish. This has lots of advantages:
  • It's faster - since the computer doesn't have to expend a lot of processing power making it look nice, it can get on with installing it quicker.
  • It's easier to install more than one thing at once - you can just specify the names of all the software packages you wish to install.
  • And of course, you get more kudos for installing from the command line!
First of all, a quick lesson. The software available for Ubuntu is kept in the repositories. Think of them as online software libraries, the contents of which are free for you to download and install. There are other repositories available (for example, Google have their own Linux repositories , from which you can download and install things like Picasa or Google Desktop), but the main ones that come preconfigured with Ubuntu are:
  • main
  • restricted
  • universe
  • multiverse
I won't explain what each one is now, we'll come to that in the future. For now, you just need to know that they are there. The software for Ubuntu comes in packages. Ubuntu uses a package format called deb packages - if you download one from somewhere other than the repositories to install it manually, you'll notice it has the .deb suffix.

Any package may depend on other programs to function - this is known as a dependency. For instance, if you install a program written in the Java programming language, you need to have the Java Runtime Environment installed. In Windows, this issue is solved by the installer including all of the dependencies within the download - so if you download Firefox, everything you need is included in that installer. This has the disadvantage that the download can be bigger than it needs to be.

Ubuntu takes a different approach. Each package consists of only the program itself, but it includes a list of all the dependencies. apt-get can use this to determine what dependencies for a package aren't yet installed, and then automatically download and install them. This means you don't have to download any more than necessary, saving you time.

That's the theory part. How does it work in practice? I'll walk you through a few basic commands. Open the command line (Terminal in Ubuntu, Konsole in Kubuntu), enter the following and press Enter. Remember, as apt-get makes changes to your system, you'll need to preface it with the sudo command each time, and you'll be prompted for your password - just use the same one you use to log in:
sudo apt-get update
This command updates your system's record of the most recent versions of packages, to make sure it's up to date. So it's good practice to run this before you install anything, in order to make sure you get the most recent version from the repositories.

What it DOESN'T do is upgrade the packages you already have installed to the latest versions. For that you need this:
sudo apt-get upgrade
If you perform these two commands regularly (say, once a week or so), you'll be able to keep up with the latest versions of everything you have installed. Unlike in Windows, you don't have to open an application and then discover it's found a more recent version, you can do it all from the same place! Don't you think that's more convenient?

Installing is easy. For instance, say you want to install the strategy game Singularity. Just enter the following on the command line:
sudo apt-get install singularity
You'll be prompted for your password. Then take a look at the resulting message:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
python-pygame singularity-data
Suggested packages:
timidity
The following NEW packages will be installed
python-pygame singularity singularity-data
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1201kB of archives.
After unpacking 3457kB of additional disk space will be used.
Do you want to continue [Y/n]?
Don't worry if yours looks a bit different to this - you may have different things installed. Notice the line saying "The following extra packages will be installed: python-pygame singularity-data". These are dependencies that Singularity relies on to work, and apt-get has picked up on that.

Now, press Y and Enter to continue. apt-get will download and install everything you need without further need for you to do anything.

There, that wasn't hard, was it? Suppose you get fed up of Singularity and want to uninstall it. Just type the following:
sudo apt-get remove singularity
and again follow the on-screen instructions. Note that when uninstalling, apt-get doesn't automatically remove dependencies that aren't required any more. If you want to get rid of these, you can use the following command:
sudo apt-get autoremove
That's it! Now you can install anything you want from the Ubuntu repositories using the command line. You do need to know the name of the package you want to install or remove, but we'll cover how to discover that later.

No comments:

Post a Comment