Ubuntu Hardy setup - page 2

Now that we've secured access to our Ubuntu Hardy slice we can update it and get it ready for the rest of the server install.


In part 1 of the Ubuntu 8.04 (Hardy Heron) setup, we completed the ssh configuration along with a basic iptables setup.

Now let's run some checks and install some personal configuration files to make life easier. Once done, we can update the install and create a solid base for the 'meat' of the server.

OS check

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

cat /etc/lsb-release

You should get an output similar to this:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.4 LTS"

Good.

Using free

Memory usage should be very low at this point but let's check using 'free -m' (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        55          199          0           2               21
-/+ buffers/cache:      30          223
Swap:            511        0           511

The line to take notice of is the second one as the first line includes cached memory - in this demo slice I have 254MB memory in total with 30MB actually used, 223MB free and no swap used. Nice.

.bashrc

Normally the "ls" command doesn't list files that start with a period. Those are usually configuration files or directories, and ls hides them so they don't clutter up your directory view. To see all of what's there, run:

ls -a ~

The "-a" option is what tells ls to list all files, not just the non-configuration files.

You'll see several files, but let's focus on ".bashrc" right now. This is ultimately where your user environment (the "shell") will look for its settings. Go ahead and open it for editing:

nano ~/.bashrc

Inside you'll see a lot of shell script commands — don't worry if you don't understand it all. Anything we add at the end of the file will override what came before. If you want to, say, change your prompt, you don't necessarily need to figure out what all the "if" statements in there by default are for, and which line you need to edit. You can just add your own setting at the end.

Custom prompt

With that in mind, let's look at how to change your prompt. At its simplest, the prompt's format is set with the "PS1" environment variable. It consists of some numbers that determine color and some codes that act as stand-ins for variables like the current working directory and your hostname. To set your prompt to just your hostname and working directory, both in different colors, you could add this line to the end of the .bashrc file:

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

The chunks like "0;35m" and "0;33m" are what control the colors - those are pink and brown, for example. Other colors you can substitute include "0;32m" for green and "0;36m" for blue — it's just a matter of changing those numbers.

Other important parts of that jumbled collection of characters are "\h" and "\w", which represent the hostname and working directory, respectively. If you wanted to include your username in the prompt you could add the "\u" code along with an "@" symbol, and it would look like this:

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

Before we see what that will look like, however, let's also look at another useful feature of your shell, aliases.

Alias

The "alias" keyword lets you set a shortcut for another command. Some examples to get you started, which can be added to the end of your .bashrc file:

alias free="free -m"
alias update="sudo aptitude update"
alias install="sudo aptitude install"
alias upgrade="sudo aptitude safe-upgrade"
alias remove="sudo aptitude remove"

They're pretty simple examples, and are just meant to save you a little typing. Notice that you can essentially replace a command with an alias, like we did by setting the alias "free" to be a shortcut for "free -m". With that alias set, when you type "free" on the command line, behind the scenes the shell actually runs "free -m", so you don't have to type the extra characters to get the memory usage numbers in megabytes.

Similarly, those other aliases are shorthand for some aptitude commands to update or install packages. Since "sudo" is run behind the scenes you'll still have to type your password, but at least before that you won't have to type as much to run an update or install a package.

To activate the changes you've made to the .bashrc file, either log out and log back in or enter this command:

source ~/.bashrc

If you set a value for "PS1" above, you'll see your prompt change. Feel free to go back and change the colors or format of the prompt, or add your own aliases.

Set locale

You can check the current locale setting for your slice by running:

/usr/bin/locale

If the code doesn't match what it should be for the localization you would like to use for your slice (or if it uses a generic locale like 'POSIX'), run something like the following commands:

sudo /usr/sbin/locale-gen en_US.UTF-8
sudo /usr/sbin/update-locale LANG=en_US.UTF-8

'Something like' because you may want to use a locale other than US English. If so, substitute the language code for 'en' and the region code for 'US' above. The locale 'cy_GB.UTF-8' would designate Welsh for the language and Great Britain for the region, for example. A complete list of language and region codes can be found here.

If you change the default locale for your slice you will need to log out and log back in to see the change when running 'locale' by itself again.

Package repositories

An Ubuntu Slice comes with a basic set of repositories.

Have a look at the enabled repositories by running:

sudo nano /etc/apt/sources.list

You should see something very much like:

deb http://archive.ubuntu.com/ubuntu/ hardy main restricted universe
deb-src http://archive.ubuntu.com/ubuntu/ hardy main restricted universe

deb http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted universe
deb-src http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted universe

deb http://security.ubuntu.com/ubuntu hardy-security main restricted universe
deb-src http://security.ubuntu.com/ubuntu hardy-security main restricted universe

Each line specifies either a binary package repository ('deb') or a source package repository ('deb-src').

You can, of course, add more repositories whenever you want to but I would just give a word of caution: Some of the available repositories are not officially supported and may not receive any security updates should a flaw be discovered.

Keep in mind it is a server we are building and security and stability are paramount.

Update

Now we can update the package list that aptitude uses.

sudo aptitude update

NOTE: If you have used the .bashrc aliases shown above you just need to enter 'update' as the alias will use the entire command. I've put the whole thing here so you know what is happening.

Now we have set the locale and updated the sources.list repositories, let's see if there are any upgraded packages available:

sudo aptitude safe-upgrade

As with all installs have a careful look at the list and, once happy, press 'y' to continue.

That's really the basics done for the Slice.

Once any updates have been installed, we can move on to installing some essential packages.

Development Tools

Ubuntu has some handy meta-packages that include sets of pre-defined programs required for a single purpose.

So instead of installing a dozen different package names, you can install just one meta-package. One such package is called 'build-essential'. Issue the command:

sudo aptitude install build-essential

Notice the programs that are to be installed include gcc, make, patch and so on. All these are needed for many other programs to install properly. A neat system indeed.

Enter 'y' and install them.

Now we have the necessary packages should we want to build an application from source.

Done

The console is now informative and less drab, locales have been configured and basic compile tools have been installed. Quite a lot happening here but now we have a more secured Slice with updated packages ready for the meat of the server to be put in place.

  • -- PickledOnion (updated by Jered)

Article Comments:

Birger J. Nordølum commented Fri Apr 25 17:21:09 UTC 2008:

bash-completion is not installed on default. So you need to add this to use sudo in a proper mather.

Birger :)

Cody commented Sun Apr 27 03:14:45 UTC 2008:

For those in the USA, use this as the system locale:

sudo locale-gen en_US.UTF-8 sudo /usr/sbin/update-locale LANG=en_US.UTF-8

Eric commented Sun May 11 19:30:55 UTC 2008:

Can you please explain why you are running both safe and full upgrade, doesn't full imply all of safe as well? How often should these commands be run, and should it be scheduled to run automatically?

PickledOnion commented Wed May 14 09:09:24 UTC 2008:

Eric,

safe and full upgrades are different commands and can upgrade different things (see the Ubuntu documentation for details).

You wouldn't need to run a full upgrade very often.

I wouldn't recommend ever running an automatic update and upgrade as they will always need supervising.

PickledOnion

Mark commented Wed May 14 10:41:26 UTC 2008:

Thanks PickledOnion - I think your tutorials are really well written

Sohail commented Mon May 19 18:09:18 UTC 2008:

PickedOnion - I've got to echo Mark. These tutorials are fantastic! They are accurate, exactly what a person needs and take the "fear" out of set up from scratch. Many of us are devs that don't muck with OS config unless we have to, so we're always rusty until the next install. Your walk throughs make setup a breeze!

This is truly a value add above and beyond that distinguishes Slicehost.com.

Great work!

Jeremy Ricketts commented Tue May 27 05:06:29 UTC 2008:

Wow. I just wanted to chime in here and say VERY well done. These tutorials are so thorough and so helpful.

Doug Johnston commented Mon Jun 02 19:47:31 UTC 2008:

To echo everyone else, these tutorials are awesome!! I've set up 3 different VPSs over the past few years and it has ALWAYS been a headache. These instructions are clear and very easy to follow. Thanks! I already have a good feeling about the move to slicehost.

Michael commented Fri Jun 06 13:07:45 UTC 2008:

Thanks for the great article, especially giving some detail about firewalling via iptables.

Keep up the great work!

Jared commented Sat Jun 07 00:33:49 UTC 2008:

@Cody Thanks! Locale in the article didn't work for this US user anyway :)

brendan lally commented Tue Jun 10 06:02:27 UTC 2008:

US needs following (; missing)

sudo locale-gen enUS.UTF-8 ; sudo /usr/sbin/update-locale LANG=enUS.UTF-8

Frank commented Fri Jun 13 17:20:04 UTC 2008:

not only are the tutorials amazing, but if you catch him in live chat, he's also a huge help

xolotl commented Mon Jun 16 06:48:11 UTC 2008:

correction missing an underscore, wouldn't that be: sudo locale-gen enUS.UTF-8 ; sudo /usr/sbin/update-locale LANG=en_US.UTF-8

MJS commented Mon Jun 16 10:43:54 UTC 2008:

This is for anyone having the same problem as me.

I couldn't get the en_GB locale file to install. It wasn't in my locale list.

So I had to run this first:

sudo locale-gen en_GB.UTF-8

PickledOnion commented Mon Jun 16 10:46:34 UTC 2008:

Hi,

The locale-gen command is the first command you run.

It is in the article before you update the locale.

You must follow the article and enter all the commands or, as you discovered, it doesn't work.

PickledOnion

MJS commented Mon Jun 16 20:58:52 UTC 2008:

Hmm, I sure I ran all the commands. But now I see it and feel like a dolt.

H commented Wed Jun 18 01:25:05 UTC 2008:

I accidentally ran "sudo aptitude safe-upgrade" before I set the locale and so I got a lot of warnings like these:

perl: warning: Falling back to the standard locale ("C"). perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_US.UTF-8" are supported and installed on your system.

The safe-upgrade command finished ok. I then set the local. Then I reran the "sudo aptitude safe-upgrade" and it didn't update anything. Does it mean the locale of my upgraded packages is now all screwed up? Do I need to re-install the slice?

Thanks.

Gokul commented Wed Jun 18 13:15:42 UTC 2008:

I had to reboot for the update-locale command to take effect.

AMR commented Mon Jul 07 16:52:30 UTC 2008:

Thanks for writing these articles. They are very helpful.

Blake Lucchesi commented Mon Jul 14 23:27:31 UTC 2008:

For those running macs and using xterm, I had an issue with my backspace key getting recognized by pico/nano. Found an easy solution here: http://www.macosxhints.com/article.php?story=20040930002324870

Thanks for the great articles PO!

adam commented Mon Jul 21 17:36:16 UTC 2008:

@blake, the mac delete problem with nano is fixed by adding;

"set rebinddelete"

to /etc/nanorc

dont include the quotes though

Philip Hallstrom commented Wed Jul 30 07:03:11 UTC 2008:

I just created a new slice and was following the directions exactly, but when I tried to set the locale, I got an error as follows:

phallstrom@TeamReadiness:~$ sudo         locale-gen en_US.UTF-8
[sudo] password for phallstrom: 
Generating locales...
  en_US.UTF-8... Killed
failed
Generation complete.
phallstrom@TeamReadiness:~$ sudo /usr/sbin/update-locale LANG=en_US.UTF-8
*** update-locale: Error: invalid locale settings:  LANG=en_US.UTF-8

Joe Cascio commented Thu Jul 31 23:43:21 UTC 2008:

adam: Thanks for the Mac hack for nano. That was driving me batty! :)

Also, great doc! I got through it in an hour or two, even though I hadn't done any unix work in literally decades!

Max commented Thu Aug 07 01:07:57 UTC 2008:

Awesome quick start guide. No bullshit just like i like it.

Bruce Giovando commented Fri Aug 08 05:26:28 UTC 2008:

Philip: I'm getting the same problem, i've tried rebooting with no luck. Anyone have any ideas?

Steve commented Sat Aug 09 02:48:44 UTC 2008:

I fixed the locales problem:

nano ~/.bashrc

Add the following two lines: export LCALL=enGB.UTF-8 export LANG=en_GB.UTF-8

source ~/.bashrc

sudo dpkg-reconfigure locales sudo /usr/sbin/update-locale LANG=en_GB.UTF-8

Jon commented Fri Aug 15 16:48:53 UTC 2008:

Great tutorials.

@Blake: I managed to solve the problem with backspace in vim by opening up ~/.vimrc and setting 'set backspace=2'. To combine that with the a fix for problematic arrow keys, etc, my .vimrc file looks like this: set nocompatible set backspace=2

Scott commented Sat Aug 16 17:29:55 UTC 2008:

I entered this command "sudo locale-gen en_US.UTF-8". But it seems to be taking a while. Is this normal?

Dash commented Sun Aug 24 04:14:40 UTC 2008:

Thank you very much for this article - its a snap now to setup my slice!

James Foster commented Mon Sep 08 03:43:07 UTC 2008:

I have a screencast where I follow these instructions. You can view it at http://programminggems.wordpress.com/2008/09/07/slicehost/

George commented Mon Sep 15 09:24:51 UTC 2008:

How do you set locale for those in Africa?

zissan commented Tue Sep 30 12:23:23 UTC 2008:

thanks a lot! you guys done some amazing works!

Dmitry commented Sat Oct 11 15:38:28 UTC 2008:

To everyone having problems with the locale commands: after fighting with them for a couple hours and screwing up my slice, I have decided to rebuild it and made a backup right before trying to set the locale. You know what - both commands worked flawlessly!

iain commented Sat Nov 01 06:21:20 UTC 2008:

Great tutorials man. Very superior work here, really gives slicehost added value, what a deal :D

Eiso Kant commented Tue Nov 11 16:13:11 UTC 2008:

Thank you for writing these, I could have never done this on my own.

Pedro Marban commented Thu Nov 13 18:04:39 UTC 2008:

I'm new to SliceHost and I've followed successfully the two great Hardy setup tutorials.

Sorry if I'm wrong but I think it is a good idea to set time synchronization with NTP: https://help.ubuntu.com/8.04/serverguide/C/NTP.html

And for the international users to change the time zone: https://help.ubuntu.com/community/UbuntuTime#Changing%20the%20Time%20Zone

PickledOnion commented Fri Nov 14 11:12:48 UTC 2008:

Hi,

NTP is running on the host server. You shouldn't need to run it on the Slice as well.

PickledOnion

Daniel Hardman commented Wed Dec 31 03:31:52 UTC 2008:

I also had a problem with the locale stuff. I tried everything in these comments, plus a bunch of other stuff after searching the web. None of it worked. Finally I noticed that my default shell was sh instead of bash. When I edited my default shell and made it bash, some of the other instructions I found worked.

Steve Cox commented Fri Jan 02 15:48:34 UTC 2009:

I agree with the ones giving praise. Both part 1 and part 2 are awesome.

I was having trouble with the locale, and did a soft reboot. WOrked fine after that.

Steve

Nes commented Wed Jan 14 07:18:03 UTC 2009:

This process was awesome and informative! I learned so much while setting my slice up. Thank you Slicehost (PickledOnion)!!!

GS commented Fri Jan 23 05:10:51 UTC 2009:

great tutorials! very little linux experience and this is making it very easy to set up a server. Thanks for the great work.

dave commented Mon Jan 26 11:06:16 UTC 2009:

Everything has worked flawlessly -- except I too am having problems with locale. Re-booted (like others), both Soft and Hard (one time), and locale still not working. Did both commands, in the order prescribed.

Also, noticed that I get 'Unable to set System Clock'(twice) when my slice is booting up. Once booted, I keep get London/UTC. Suggestions?

James Godwin commented Fri Feb 06 18:57:09 UTC 2009:

Simply beautiful. The tutorial reads like a poem

John commented Sun Feb 22 20:11:56 UTC 2009:

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

I don't get the current directory in brown using this...

jared commented Sat Feb 28 04:06:35 UTC 2009:

Even though I set the locale correctly, which is required to update packages, the local time (displayed by doing 'date') was set to UTF, not my local time.

Had to do 'sudo dpkg-reconfigure tzdata' to get the right timezone.

Jesse commented Sat Mar 07 06:49:47 UTC 2009:

Thank you for this article this helped me get on track and up to speed, as well as the slicechat -- but after going over this three times I am really starting to see how things work! Thank you!

Florida Web Design commented Mon Mar 16 03:47:59 UTC 2009:

This page is much more intuitive than Page 1 of this setup. I had a terrible time doing visudo, as well as the Private/Public pair deal with Windows.

Clive commented Fri Apr 10 15:31:11 UTC 2009:

To echo George, what is the command for locale Africa?

Chip commented Sun Apr 19 09:34:57 UTC 2009:

To find the country code for your country, google for 'ISO 3166'. It's a document that lists the two letter codes for various countries.

Then do: "nano /usr/share/i18n/SUPPORTED" and see if that code is listed. If so, you should be good to go.

Alex commented Sat Apr 25 06:35:48 UTC 2009:

What command have to be for locale Russian/Ukraine?

Jordan Lev commented Sat May 02 00:29:37 UTC 2009:

@Alex, I believe the Russian locale would be "ruRU.UTF-8", and the Ukrainian locale would be "ukUA.UTF-8" (but I'm not 100% sure).

George Tuvell commented Thu May 07 04:04:10 UTC 2009:

If you are getting a "connection refused" error when you try to login via SSH after doing the SSH reload command, make sure that you have the port open in the iptables that matches the port you setup in the SSHDConfig. (i.e. it's defaulted to port 3000 in the iptables, but u need to change this number in the IPtables to the port you chose in the SSHDConfig.) They must match!

This one took me some time to solve..hope it helps.

Dave commented Fri May 22 08:32:50 UTC 2009:

Sweet Tutorial! - Thanks a million!

Bergen commented Sun Aug 02 05:11:15 UTC 2009:

Pickled Onion: You are an inspiration to the rest of us crappy documentation writers everywhere... and so good in a martini!

I too, get rusty on this stuff, and frankly, a little scared and cowardly and unorganized... and then it's 5am. Not this time. Thanks.

Adds value, for sure.

Florida Software Development commented Thu Nov 12 16:44:50 UTC 2009:

Nice article. I skipped the coloring of the console part, but I did the rest of Page 1 and Page 2. Thanks PickledOnion.

Ruk commented Tue Nov 17 10:14:03 UTC 2009:

PickledOnion,

after getting my new 256 slice I realized that the "default" memory usage with "nothing running" is around 120MB instead of 26MB. This pretty much changes everything as the available RAM is limited by default to ~130 (instead of ~230 pointed out by this article).

According to support this is due to more modern kernels consuming more memory.

Nonetheless, it would be nice to update the free-m screenshot on the tutorial since it may give false expectations.

Thanks

NiKoZ commented Tue Dec 15 08:37:19 UTC 2009:

for the locales error messages try:

sudo apt-get install --reinstall language-pack-en language-pack- (yourlanguage code)

Richard commented Wed Jan 27 19:51:20 UTC 2010:

@ruk I have a 108mb memory usage after a clean install as well.

Dave commented Tue Feb 02 22:01:41 UTC 2010:

I never post comments but got feel I ought to as that this tutorial truly rocks. Skills Pickled Onion.

Margaret commented Wed Mar 17 16:44:46 UTC 2010:

Another note of thanks for the clear and simple instructions. It's been years since I did this and I was prepared for hours of fiddling to get it all done. Suddenly the rest of my afternoon is free. Thanks Pickled Onion. :)

Busara commented Fri Apr 23 20:43:00 UTC 2010:

Thanks Pickled for sharing your awesome tutorials - this Hardy series is absolutely perfect for me. All instructions are easy to read and follow, so thanks again for helping out the learning users such as myself!

Paul Trippett commented Fri May 28 18:40:25 UTC 2010:

And an additional thankyou for taking the time to help the community with these great articles

binunda commented Wed Oct 06 19:26:10 UTC 2010:

Great stuff. Easy to follow.

Email Marketing commented Tue May 07 09:13:05 UTC 2013:

Hi there, all is going perfectly here and ofcourse every one is sharing information, that's in fact excellent, keep up writing.

Feel free to surf to my webpage - Email Marketing

toms botas for sale commented Mon May 13 10:55:57 UTC 2013:

Excellent web site. Lots of useful info here. I'm sending it to some friends ans additionally sharing in delicious. And obviously, thanks in your effort!

crack commented Tue Aug 06 20:22:29 UTC 2013:

each time i used to read smaller posts which as well clear their motive, and that is also happening with this post which I am reading now.

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)