Skip to main content

How to Fix SSH Locale Environment Variable Error

locale environment variable

What is Locale environment variable? In Linux, a locale consists of four categories of environment variables:

  2. LC_ALL
  4. LANG

These environment variables define the system language, monetary format, date and time format etc. on your Linux distribution. You can check out your locale environment variables by running the locale command in terminal:


Sample output:


You can see that the above output contains all four categories of locale environment variables.

On Ubuntu, you can set LANGUAGE, LANG and LC_* variables graphically in system settings > language support.

locale environment variable

Systemd-based Linux distributions (Debian 8+, Ubuntu 15.04+, Fedora, CentOS7+, Arch Linux) can use this command to set each locale environment variable.

sudo localectl set-locale variable_name=value

For example, set LANG=en_US.UTF-8.

sudo localectl set-locale LANG=en_US.UTF-8

Locale changes may need re-login or reboot to take effect.

SSH Locale Environment Variable Error

When you ssh into a remote Linux server, you might see the following error or errors related to locales settings.

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LC_TIME = "zh_CN.UTF-8",
        LC_MONETARY = "zh_CN.UTF-8",
        LC_ADDRESS = "zh_CN.UTF-8",
        LC_TELEPHONE = "zh_CN.UTF-8",
        LC_NAME = "zh_CN.UTF-8",
        LC_MEASUREMENT = "zh_CN.UTF-8",
        LC_IDENTIFICATION = "zh_CN.UTF-8",
        LC_NUMERIC = "zh_CN.UTF-8",
        LC_PAPER = "zh_CN.UTF-8",
        LANG = "en_US.UTF-8"
        are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

Why does this locale error happens? Well, that’s because your ssh client forward your locale environment variables from your local computer to the remote Linux server which doesn’t have the needed locale generated.

This happens a lot if you are not a native English speaker. Normally you would configured a different language other than English on your computer. But most Linux server by default only have English locales generated.

Fixing the Error: Method 1

To fix this error, you can generate the needed locales on the Linux server. First open the /etc/locale.gen file.

sudo nano /etc/locale.gen

Find the needed locale and remove the # sign to uncomment. For example, to generate zh_CN.UTF-8 locale, find this line:

#zh_CN.UTF-8 UTF-8

Remove and # sign. Save and close the file. Then run the following command to generate it.

sudo locale-gen

locale-gen reads /etc/locale.gen file to know what locales to generate. You can also generate multiple locales by uncommenting multiple lines in that file.

Fixing the Error: Method 2

We can also disable ssh locale environment variable forwarding to fix this error. Open the ssh client configuration file on your local computer.

sudo nano /etc/ssh/ssh_config

Find this line:

SendEnv LANG LC_*

Add a # sign at the beginning to comment it out. Save and close the file.

Questions or suggestions are always welcome. If you found this post useful, 🙂  please share it with your friends on social media! Stay tuned for more Linux tutorials.

Rate this tutorial
[Total: 1 Average: 3]