How to change locale settings

From RCSWiki
Jump to navigation Jump to search


In computing, a locale is a set of parameters that defines the user's language, region and any special variant preferences, that the user wants to see in their user interface. Usually a locale identifier consists of at least a language code and a country/region code.

For example, a locale setting for your computing environment will affect the presence of special characters, sorting order, as well as some other values, such as the currency symbol.

The Issue

It is convenient to have the locale of your computer set to your preferred value. However, when you use your SSH client to connect to a remote computer, such as the ARC cluster, the SSH client will translate your locale settings to your remote session on the remote computer. It will set the current locale to the value you have on your personal computer. The problem will arise if such a locale is not available on the remote computer.

In addition, the compute nodes in ARC have less software and tools installed in their environment, to save space. Thus, even though the locale your SSH client sets, may be available on ARC's login node, it may not be available on the compute nodes.

If the locale that was communicated and set by your SSH client is not available on the remote system, it will show itself when a locale aware program starts. The system will be printing annoying warnings.

For, example, when starting an interactive R session:

$ R
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (CA.UTF-8)

R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"

sh: warning: setlocale: LC_ALL: cannot change locale (CA.UTF-8)
sh: warning: setlocale: LC_ALL: cannot change locale (CA.UTF-8)
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C" 
5: Setting LC_MONETARY failed, using "C" 
6: Setting LC_PAPER failed, using "C" 
7: Setting LC_MEASUREMENT failed, using "C" 

How to Correct

In principle, these are not errors, these are warnings, and your software may be working just fine, even in this case. But it may be annoying and worrying to have them in the output. And some software may actually be not working properly, on rare occasions.

This is how to correct it:

  • Check the current locale
$ locale
  • See the available locales
$ locale -a
  • Set the locale to something available (and generic) and test if this solves the problem.
$ export LC_ALL=C.UTF-8
$ export LANG=C.UTF-8
C or C.UTF-8 are the most generic choices.
  • If the solution works, update your .bashrc configuration files with these settings.
$ nano ~/.bashrc

Your ~/.bashrc should look something like this:

# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc

export LC_ALL=C.UTF-8
export LANG=C.UTF-8

The ~/.bashrc file is executed when a user logs into his/her account interactively. The SSH client will set the locale on ARC as it is set on the personal computer, but the .bashrc will run after that and will reset the locale settings to the proper and available locale.

This should resolve the locale issue.