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: , , , , ,

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

Anonymous said...

Why don't you fix the problem in the program that can't handle UTF-8 instead? Everyone should be using UTF-8 at this point.

Anonymous said...

I agree with anonymous above. You should all be using UTF-8 as it is the standard. iso-8559-1 is so last century.

Allen said...

Thanks. I was looking for a solution.

Tim said...

Wow..finally!

Janaka Vishwajith said...

I got success through

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

I needed pull some sinhala BLOB data from db, finally did it through above update.
Thnx Daniel....

Anonymous said...

The above didn't work for me. All I needed to do was add the following to my .profile (use .bash_profile if it exists instead as it has a higher priority)

inside .profile or .bash_profile in the users home directory:
LANG=en_US.ISO-8859-1

Then logout and back in.
locale
echo $LANG
confirm that it has been successful

Anonymous said...

thankyou!
Moreover, if anyone needs legal locale codes, are in:

/usr/share/i18n/SUPPORTED

Anonymous said...

I got an Ubuntu Lucid vmware image that came with the en_US.UTF-8 locale and wanted to change it to use en_GB.UTF-8. This is the first page google came up with so I thought I'd post my findings.

cat /var/lib/locales/supported.d/local

Does the desired locale exist in there? If not then create it with

sudo locale-gen en_GB.UTF-8

It will genetate the locale and update the list of supported locales. Now change the default locale with

sudo update-locale LANG=en_GB.UTF-8

It updates the contents of /etc/default/locale. Log out and back in again. You can check that it has taken affect by typing locale

Cameron Kerr said...

The easiest way on Debian-based distributions is to use "sudo dpkg-reconfigure locales".

This will ask you which locales you wish to generate, and which of those you want to be the default.

Problem fixed.

Anonymous said...

/etc/default/locale

Thank you so much!

Anonymous said...

Thanks a lot

sebwebdev said...

For German use:

locale-gen de_DE
update-locale LANG=de_DE@euro

Anilikos said...

trully thankfull, have tried to solve this thing on natty for almost a day

Anonymous said...

it crashed my Ubuntu 11.04

Felipe 'chronos' Prenholato said...

Just saying thanx :), u solved my problem.

Anonymous said...

Thank you very much,
you solved my problem as well !
for Egypt/Arabic use ar_EG

Mat said...

Sweet. Worked perfectly!

Anonymous said...

Thanks !

Etienne