- 1 Introduction
- 2 Enabling necessary locales
- 3 Setting system wide locale
- 4 Collation
- 5 Setting per user locale
- 6 Setting starting weekday
- 7 Troubleshooting
- 8 Links
Locales are used in Linux to define which language the user uses. As the locales define the charset which the user uses as well, setting up the correct locale is especially important if the language contains non-ASCII characters.
Locale Naming ist defined as following:
In this howto we're setting up a system that uses the en_US.UTF-8 locale, but you can follow this article easily if you want to setup another locale.
Enabling necessary locales
First you have to enable the locales you want being supported by your system. To enable or disable them, the file /etc/locale.gen is used. It contains every locale you can enable, and you have just to uncomment lines you want to do so.
As we want to setup an english UTF-8 conform system, we want to enable en_US.UTF-8. But for compatibility to programs that don't support UTF-8 yet, it's recommended to support any other locale, prefixed with en_US as well. Having this in mind, we enable this set of locales:
en_US.UTF-8 UTF-8 en_US ISO-8859-1
After you've enabled the necessary locales, you have to run locale-gen as root to update them:
# sudo locale-gen Generating locales... en_US.UTF-8... done en_US.ISO-8859-1... done Generation complete.
Note: Though it's most likely just one language you use on your computer it can be helpful or even necessary to enable other locales as well. For example if you're running a multi-user system with users that don't speak en_US, they won't be happy until their individual locale is at least supported by your system.
Setting system wide locale
To define which locale should be used by the system, you can easily add your locale to your /etc/rc.conf file. As we've just added ISO-8859 support just for (backward-)compability, we add en_US.UTF-8 here:
The system wide locale will be updated after rebooting your computer.
Collation, or sorting, is a little different. Sorting is a goofy beast and different locales do things differently. To get around potential issues, we have set LC_COLLATE="C" in /etc/profile. This forces collation to "C mode". This is usually a good idea for most users. If you want to overwrite this with sorting rules from your locale, it is best to do one of the following:
- Modify the line in /etc/profile directly
- Comment out the LC_COLLATE line in /etc/profile (allowing locale aware apps to use LC_ALL or LOCALE)
- Manually set LC_COLLATE in addition to LC_ALL or LOCALE in your user profile
Setting per user locale
As we discussed earlier, some users might want to define a different locale than the system-wide locale. In this case, you can export LANG in your ~/.bashrc. For example you can use the en_AU.UTF-8 locale.
Your locales will be updated as soon as you re-source your ~/.bashrc. This happens on login or alternatively you can type:
$ source ~/.bashrc
Setting starting weekday
In a lot of countries the first day of the week is Monday. To do change or add the following lines under the LC_TIME section in /usr/share/i18n/locales/<your_locale>
week 7;19971130;5 first_weekday 2 first_workday 2
And then run
and restart X.
How can I obtain the available locale names?
You can get the correct names of all available locales with this command:
$ locale -a
How can I see which locale I am using?
Which locale is currently in use is viewable simply by typing:
My terminal doesn't support UTF-8 characters
Unfortunately some terminals don't support UTF-8. In this case, you have to use a different terminal.
List of terminals that support UTF-8:
- urxvt (rxvt-unicode)
Note: This list may be incomplete.
xterm doesn't support UTF-8 characters for me
xterm only supports UTF-8 if you run it as uxterm or xterm -u8.