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: Ubuntu, Linux, Locale, Unicode, UTF8, Andrew Beacock


29 comments:
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.
modify "/etc/default/locale".
that will fix your problem
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!
Hi Andrew,
That worked out well.
Thanks for this information!
Magnificent!! Searched for hours to try and change this because its stopping em installing DBD::ODBC.....I owe u pint!
Excellent!
Solved a problem with a stubbornly German Hotel booking program, CultBooking.
Cheers
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.
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.
Hi,
thanks a lot. Anyway, the reboot is not needed.
Ciao,
Andrea
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.
brilliant!
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.
I agree with anonymous above. You should all be using UTF-8 as it is the standard. iso-8559-1 is so last century.
Thanks. I was looking for a solution.
Wow..finally!
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....
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
thankyou!
Moreover, if anyone needs legal locale codes, are in:
/usr/share/i18n/SUPPORTED
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
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.
/etc/default/locale
Thank you so much!
Thanks a lot
For German use:
locale-gen de_DE
update-locale LANG=de_DE@euro
trully thankfull, have tried to solve this thing on natty for almost a day
it crashed my Ubuntu 11.04
Just saying thanx :), u solved my problem.
Thank you very much,
you solved my problem as well !
for Egypt/Arabic use ar_EG
Sweet. Worked perfectly!
Thanks !
Etienne
Post a Comment