Step five: Prepare to add applications
Before we start installing software we need
to update the application database. Type: sudo apt-get update
Before
we start installing software we need to update the application database. Type:
sudo apt-get update
This downloads the latest package
information from the Ubuntu repositories, so that you have the most up-to-date
data. Then we should update the software itself: sudo apt-get upgrade
This will apply all of the updates and
bugfixes since the server CD was released. Note: This does not upgrade the
distro version.
You should now have a working server. Over
the course of this series we will look at using it to fulfil various roles.
If you wish, you can try out a few commands
from the boxout. When you’ve finished, you can shut down your server until next
time, with this command: sudo shutdown -h now
Navigating
the CLI
Besides typing commands, there are a few useful
tips that are worth knowing:
- The up and down keys will scroll through
recently used commands.
- The Tab key will auto-complete file
names, commands, etc.
- Ctrl+C will stop a running process.
- Commands can be copied and pasted into
the terminal from websites or documents, etc. (I will be posting them on
the Micro Mart forum for this very purpose).
- Exit will log you out.
Commands
Throughout these tutorials, we’ll be using
a few commands repeatedly, some of which are listed below. All of these
commands have many options, but I’ll only list relevant ones to keep things
simple. During the series, we’ll come across other commands, and they’ll be
explained as and when they’re used. Those of you who do not have any experience
with the Linux command line should note that unlike DOS, it’s case-sensitive.
So ‘Desktop’ is not the same as ‘desktop’, for example. Commands are usually
all lower case, but not always, and folder names are sometimes capitalised. As
we travel through the tutorials, we’ll see some of the power of the Linux
command structures.
As
we travel through the tutorials, we’ll see some of the power of the Linux
command structures.
sudo - This temporarily gives us superuser
status, which is needed for installing software or making changes to the system.
The rest of the time, you operate as a standard user. This is a security
precaution, a little like User Account Control in Windows. Usage is ‘sudo
command’. You will then be asked for your password.
cd - The change directory command.
cd .. - Will move up one level.
cd / - Will move to the root directory.
cd /etc - Will move to the /etc directory,
and so on.
cp - The copy command. Usage is ‘cp
sourcefilename destinationfilename’. For example, ‘cp mypicture.jpg mypicture2.
jpg; copies the file mypicture.jpg and names it mypicture2.jpg or ;cp
/home/leo/pictures/mypicture.jpg /home/leo/Desktop/’ copies the same file, but
puts it on the desktop.
ls - The list command, used to list the
contents of a directory. Ls will list the contents of the current directory. ls
/etc will list the contents of the /etc directory.
mv - The move command, also used to rename
files. For example, ‘mv mypicture.jpg mypicture2.jpg’ will rename mypicture.jpg
to mypicture2.jpg or ‘mv /home/leo/pictures/ mypicture.jpg /home/leo/Desktop/mypicture.jpg’
moves the same file to the desktop.
pwd - Print working directory. Returns the
current directory, which is useful if you lose your way.
rm - the remove command, used to delete
files. For example, ‘rm mypicture.jpg’ deletes the file mypicture.jpg.
ssh - Used to create a secure encrypted
connection between two PCs. When first launched, it asks you if you want to
install the server’s SSH certificate on your PC. The shared certificate is then
used to encrypt future connections
nano - A CLI based text editor. Unlike some
of the more complex offerings such as vi or emacs, it’s fairly intuitive and
easy to use. Usage is ‘sudo nano filename’.
top - Shows processes running, memory used,
system load, etc. The load is calculated as a combination of resources. This
includes processor, memory, swap, chipset and network. This figure can guide
you as to the stress on your PC. Ideally you want it below 75% for reliable
performance. A load figure of 1 means 100% load for a single CPU. My hardware
has 2 cores with Hyper-Threading, so it’s counted as four CPUs, making 100%
total load equal to a load factor of 4.0. I’ll be happy if it stays below 3.0.
If it rises above 6.0, the system will be really struggling. The basic system
as configured on this hardware gives an average system load of 0.0 to 0.1.
Pressing ‘1’ (the number one) will show the
CPU figures separately. Press ‘q’ to quit.
I will be giving the load average from top
for each project in the series. This is a rough guide for comparison purposes
only, but it can give you an idea of how your hardware will perform on
different tasks.
shutdown - Logically enough, this shuts
down your PC. Although a server usually runs constantly, occasionally you need
to shut it down or reboot. You have to specify a shutdown mode and a time.
sudo shutdown -h now - Halts (powers down)
your PC.
sudo shutdown -r now - Reboots your PC.
Installing
software from the command line
There are several options for doing this.
apt-get install - This will download and
install a package and all of its relevant dependencies. Provided that the
package you want exists in the Ubuntu repositories (and there are literally
thousands of packages), you can use apt-get to download and install it and all
its dependencies in one operation.
Installing
software from the command line
Usage is ‘apt-get install packagename’. You
need to know the exact name of the package. For example, to install Java
execute these two commands, one after the other.
sudo apt-get update
sudo apt-get install openjdk-6-jre
It is always advisable to run apt-get
update before installing a package, as that ensures that your local apt
database is up to date. The install command gives you a list of packages that
will be installed. Type ‘y’ and hit Enter to continue. As we shall see, using
apt-get it’s possible to install some surprisingly complex packages.
aptitude - This will launch a menu based
interface for installing apt packages.
tasksel - This will give you a menu-based
interface for installing particular application bundles, such as a LAMP server,
already configured.
Not
in the repository
Unfortunately, some packages are excluded
from the standard Ubuntu repositories. This can be for a variety of reasons,
such as a non-free license, a dependency on non-free libraries, not meeting
compatibility or reliability standards, or just because nobody has packaged
them.