当我运行perl时,我得到警告:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

我该怎么解决呢?


当前回答

如果您正在使用反引导创建rootfs,则需要生成区域设置。你可以通过运行:

# (optional) enable missing locales
sudo nano /etc/locale.gen

# then regenerate
sudo locale-gen

这个技巧来自https://help.ubuntu.com/community/Xen

其他回答

在我的情况下,使用Debian 8.6 (Jessie),我必须更改设置:

/etc/ssh/ssh_config` for `#AcceptEnv LANG LC_*

and

sshd_config为SendEnv LANG LC_*

然后重新启动ssh服务。

最后,我做到了:

locale-gen en_US。UTF-8和dpkg-reconfigure区域设置

将缺失的地区添加到.bash_profile文件中:

echo "export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8">>~/.bash_profile

然后来源你的.bash_profile文件:

source ~/.bash_profile
sudo nano /etc/locale.gen

取消注释你想要使用的地区(例如en_US。utf - 8 utf - 8):

然后运行:

sudo /usr/sbin/locale-gen

来源:配置区域设置

以下是如何在Mac OS X v10.7 (Lion)或Cygwin (Windows 10)上解决这个问题:

在主机上的bashrc或bash_profile文件中添加以下代码行:

# Setting for the new UTF-8 terminal support in Lion
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

如果你使用Z shell (zsh),编辑文件zshrc:

# Setting for the new UTF-8 terminal support in Lion
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8

你的操作系统不知道en_US.UTF-8。

你没有提到具体的平台,但我可以重现你的问题:

% uname -a
OSF1 hunter2 V5.1 2650 alpha
% perl -e exit
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

我猜您使用ssh从一台新的桌面计算机连接到这台较旧的主机。通常在/etc/ssh/sshd_config中包含

AcceptEnv LANG LC_*

它允许客户端将这些环境变量的值传播到新的会话中。

如果你不需要完整的区域设置,警告会提示你如何压制它:

% env LANG=C perl -e exit
%

或与Bash:

$ LANG=C perl -e exit
$ 

要想永久解决问题,请选择其中之一

在旧的主机上,在shell的初始化文件中设置LANG环境变量。 在客户端修改环境,例如,使用命令LANG=C ssh hunter2而不是ssh hunter2。 如果您拥有管理员权限,可以通过注释掉本地/etc/ssh/ssh_config文件中的SendEnv LANG LC_*行来阻止ssh发送环境变量。(多亏了这个回答。有关更多信息,请参阅OpenSSH中的Bug 1285。)