How to change your default locale on Ubuntu Linux

One problem that has repeatedly cropped up when developing in Java is strange error messages in our unit tests for certain text manipulation tests when running on a freshly installed Ubuntu desktop.

They are all related to Ubuntu's default British locale: en_GB.UTF-8

This was causing files checked out of CVS to be in Unicode (UTF-8) format rather than ISO-8859-1 and so the British pound sign (£) was being encoded as a double-byte (rather than single-byte) character in the file.

To check which locale you currently have as your default just run: locale

Changing the default locale is a little different on Ubuntu compared to most Linux distros, these are the steps we needed to go through to get it changed:

Add the locale to the list of 'supported locales'
Edit /var/lib/locales/supported.d/local and add the following line:
en_GB ISO-8859-1

Regenerate the supported locales
Run sudo dpkg-reconfigure locales

Change the default locale
Edit /etc/environment and ensure the LANG and LANGUAGE lines read as follows:
LANG="en_GB"
LANGUAGE="en_GB:en"


UPDATE '09: An old collegue has suggested that this change should now be made in /etc/default/locale rather than /etc/environment - Thanks Guy!

Reboot!

Rerun locale to check that your default locale is now en_GB

Technorati Tags: , , , , ,

11 Comments:

rascassian said...

Hi Andrew,

I've installed Kubuntu onto a laptop with a US keyboard, hence I believe the Kubuntu installer configured linux to the en_US locale. I've followed the configuration instructions you mentioned to change locales (I guess it would be similar under Kubuntu), however, my LANG variable is still set as en_US.UTF-8 as are a number of other LC vars. The only change is that of the addition of a LANGUAGE var which is set to en_GB:en. Any idea where these other settings are configured and how I can get them changed?

Thanks,

Andy.

Anonymous said...

modify "/etc/default/locale".
that will fix your problem

peter said...

Interesting that we have to resort to editing obscure files when there is a GUI to do the dirty work.
I set (in Kubuntu) country or region to Tanzania and language to british english.
Spell checking in kmail etc was using US spelling and open office use $ for currency.
I have a file /etc/environment that says
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
LANG="en_US.UTF-8"
and a file /etc/default/locale which says
LANG="en_US.UTF-8"
the locale command lists everything based on en_US

Wouldn't it be good if the GUI settings actually worked and set things as I wanted!

Sur Max said...

Hi Andrew,

That worked out well.
Thanks for this information!

Anonymous said...

Magnificent!! Searched for hours to try and change this because its stopping em installing DBD::ODBC.....I owe u pint!

web site design liverpool said...

Excellent!

Solved a problem with a stubbornly German Hotel booking program, CultBooking.

Cheers

Dario said...

I love that everytime I had a problem with my computer, someone else has already solved, haha.

My two cents are that, as far as Ubuntu Hardy, I also needed to change

/etc/default/locale

Regards.

Stephen O'Neill said...

You're my hero, thanks! I was getting perl warnings about the LOCALE not being configured correctly.

I don't any more - your suggestion worked where others didn't.

Gelma said...

Hi,
thanks a lot. Anyway, the reboot is not needed.

Ciao,
Andrea

Daniel Norton said...

This works for me in Ubuntu 8.10 (and might work in earlier versions):

locale-gen en_GB
update-locale LANG=en_GB.ISO-8859-1

I recommend UTF-8 and here's what I used:
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8

I did not need to reboot, but I did need to log out and log back in again before the output of "locale" reflected the changes. The reboot might be necessary for background processes to reload the new information.

brokenladder said...

brilliant!