How to Fix SSH Locale Environment Variable Error
What is Locale environment variable? In Linux, a locale consists of four categories of environment variables:
- LC_*: LC_TYPE, LC_NUMERIC, LC_TIME…
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:
LANG=zh_CN.UTF-8 LANGUAGE=zh_CN LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC=en_US.UTF-8 LC_TIME=en_US.UTF-8 LC_COLLATE="zh_CN.UTF-8" LC_MONETARY=en_US.UTF-8 LC_MESSAGES="zh_CN.UTF-8" LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8 LC_ALL=
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.
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
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:
Remove and # sign. Save and close the file. Then run the following command to generate it.
/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.