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"


Reboot!

Rerun locale to check that your default locale is now en_GB

Technorati Tags: , , , , ,

5 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!