Ubuntu setup - page 2

In page 1 we completed the ssh configuration along with a slick iptables install. Let's move on and install some personal configuration files to make our life easier. Once done, we can update the software.

First thing is to confirm what OS we're using. We know we should be using Ubuntu LTS but let's check:

cat /etc/issue

You should get an output similar to this:

#Ubuntu 6.06 LTS \n \l

Now let's see how our memory usage is doing (the -m suffix displays the result in MB's which I find easier to read).

free -m

It's nice to know what is going on so let's look at that output:

.                  total       used       free     shared    buffers     cached
Mem:             254        68         185          0          2            38
-/+ buffers/cache:        27         227
Swap:            511        0           511

The important line is the second one as the first line includes cached memory - in this test VPS I have 254MB memory in total with 27MB actually used, 227MB free and no swap used. A good start I think.

Let's make the terminal a bit prettier and bit more useful by adding a few lines to our .bash_profile file.

nano ~/.bash_profile

We need to add a few lines at the end of the existing text. The following line will make the terminal show the server name in colour and display the working directory (the directory we are in) in a different colour:

export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '

Now we'll add some aliases to the file. Aliases are simply short cuts to commands or sequences of commands. I've included a few below but you can have as many or as few as you want.

alias free="free -m"
alias update="sudo apt-get update"
alias install="sudo apt-get install"
alias upgrade="sudo apt-get upgrade"
alias remove="sudo apt-get remove"
alias gem="sudo gem"

The examples above are pretty simple. Instead of typing 'free -m' every time I want to look at the memory usage, I just type 'free. Typing 'sudo apt-get install' can get tedious, so I just type 'install'. I still need to provide my password for the command to work, but it is more productive/quicker/easier to have short cuts.

To make our terminal use the changes we can either log out and log in again (a bit much!) or issue the following command:

source ~/.bash_profile

You should now see the VPS name in purple and the working directory in brown. To change the colours to your choosing, adjust the 0;35m and the 0;33m values in the 'export PS1' line of your .bash_profile. For example:

export PS1='\[\033[0;32m\]\h\[\033[0;36m\] \w\[\033[00m\]: '

would give you a green and blue output.

Fun time over! We need to update the software catalogue now, but first some adjustments need to made the sources list that the OS uses. So open up the file:

sudo nano /etc/apt/sources.list

I've put up an example sources list. I simply delete the contents of the original and replace with the list shown in the link. You can add or delete sources as you see fit. A word of warning about adding a 'backports' repository: they are unsupported and we're building a server here, not a desktop - we need stability and durability.

Once the sources.list is updated, issue the command:

sudo apt-get update

NOTE: If you have used the .bash_profile shown above, you do not need to give the whole command. You just need to enter 'update' and the alias will give the entire command. I've put the whole thing here so you know what is happening. Use either the alias you have set up or the whole command.

From the terminal output you will see the download of the updated package list.

The first thing we need to do is install some language packs. In my case I install the english ones. You may have to change it to your chosen language. We do this before updating anything else so the install does not throw up warnings and errors about locations and so on.

sudo apt-get install localeconf language-pack-en

NOTE: I won't mention it again (honest!), but if you use the .bash_profile aliases, you only need to type in 'install package_name' and not the whole command shown above.

Review what it's going to install and press 'Y'.

The install will ask a couple of questions: Answer 'yes' to both.

Now let's update the installed software to the latest Ubuntu LTS ones. The LTS is important here - Ubuntu LTS has guaranteed 5 years of security updates to all the programmes. Remember that we are building a server here and not a desktop and we need that long term stability.

sudo apt-get upgrade

Have a look at what is going to happen and press 'Y'.

That might take a little while to finish and when it is done we're going to reboot the server. It's the only time this will happen and we need to do it as there may have been some significant changes in the base/minimal install. It simply ensures that all the init files and configurations are running nice and smoothly.

sudo shutdown -r now

That command tells it to shutdown, reboot and to do that right now!

You will be 'thrown' off the terminal. Wait a minutes or two (it doesn't take long) and log back in again. If you want, you can also see the output of the reboot via the Ajax console in the Slicehost control panel. Just login and click 'console' next to your slice name. It's not essential to view it, but if you are new to servers, it can give a good idea of what happens in the boot process and may give an idea if something goes wrong. Obviously, you can view the logs as well, but this is a nice and easy way of seeing the 'live action'.

My reboot took about 15 seconds. Now log back in:

ssh -p 30000 paul@YOURIPADDRESS

First thing to do is install 'screen'. This is a great utility that allows us many 'virtual' terminals in our single terminal window. It also has the ability to start a process and be left to it. The connection could drop or you can log out and log in again later to see how the process is doing. A 'normal' ssh connection will not do that - if the connection drops, the process stops which is very annoying when you're an hour into compiling GCC, as you have to start again!

So, let's install screen:

sudo apt-get install screen -y

Did you notice the -y at the end of the command? This tells the install to go ahead and not ask if I want to carry on. Not always recommended but it's safe here.

If you've never used screen before, have a look at this screen tutorial which also includes how to create a .screenrc file so it start exactly how you want it to (my screen session starts with 3 terminals, one running 'top, one main work terminal and a spare terminal for other use).

Let's start simply:

screen

Press the 'Space Bar' and it looks just like the normal terminal, except the colour has gone... Simply issue the 'source' command:

source ~/.bash_profile

Now we are back to using our aliases and useful bash prompt.

That's it for page 2.

In page 3, we're going to install the 'essential' programmes that are needed by most installs. Then we get to the real point of the server and install a mysql and Ruby on Rails stack with subversion support.

PickledOnion.

Digg it | del.icio.us | reddit | StumbleUpon

Article Comments:

Colin 30 Jul, 2007

Is there any way to have this command be persistent when using screen?

export PS1='[\033[0;35m]\h[\033[0;33m] \w[\033[00m]: '

PickledOnion 30 Jul, 2007

Colin,

Short answer is not that I know of. There may be a way of implementing it with a shell script but I have not investigated it.

If you do find a way, could you let me/us know?

Cheers, PickledOnion.

Comments are closed for this article.