当我运行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").

我该怎么解决呢?


当前回答

仅适用于macOS和Mac OS X用户

我在使用Git时也得到了同样的警告

要解决此警告,取消选中“在启动时设置语言环境变量”选项并重新启动终端。下面的屏幕截图代表了我的终端设置。

其他回答

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

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

# then regenerate
sudo locale-gen

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

perl -e exit
sudo localedef -i en_US -f UTF-8 en_DE.UTF-8
#                                   DE = German
# Use your country code en lieu of  DE

# The second "perl" should then not complain any more
perl -e exit

localectl list-locales # Just make sure it is OK

如果不关心语言环境问题,可以设置PERL_BADLANG=0。当然,这可能导致不正确的本地化。

在我的例子中,这是输出:

LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "ro_RO.UTF-8",
LC_ADDRESS = "ro_RO.UTF-8",
....

解决方案是:

sudo locale-gen ro_RO.UTF-8

对我来说,我通过编辑.bashrc文件,添加导出来修复这个错误。添加在最初的注释之后。

添加语言支持。

export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_TYPE=en_US.UTF-8