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

我该怎么解决呢?


当前回答

这在Ubuntu中很简单。您必须从头开始生成locale,从命令行运行以下命令:

sudo locale-gen en_US en_US.UTF-8
sudo dpkg-reconfigure locales

这将创建区域设置,然后重新配置它们。

其他回答

我在/etc/locale.conf上设置了LC_COLLATE=C。我简单地删除了这一行,因此只有LANG=en_US。设置了UTF-8(或等效的UTF-8),就不会再有问题了。

对于Ubuntu Server和Debian:

不需要在bashrc中创建导出或处理dpkg-reconfigure。

只需将/etc/default/locale的内容替换为:

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8

将缺失的地区添加到.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

我们将设置重启后不会取消设置的区域设置。

首先打开Bash文件并编辑它:

nano .bashrc

将这些行添加到文件中:

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

通过重新加载Bash激活更改:

source ~/.bashrc

测试结果:

locale

每当我在最新的Kali Linux版本上运行Perl脚本(比如enum4linux)时,都会遇到这个问题。

kali@kali:~$ lsb_release -a
No LSB modules are available.
Distributor ID:    Kali
Description:    Kali GNU/Linux Rolling
Release:    2020.3
Codename:    kali-rolling
kali@kali:~$

例如,

kali@kali:~$ enum4linux
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_ADDRESS = "ms_MY.UTF-8",
    LC_NAME = "ms_MY.UTF-8",
    LC_MONETARY = "ms_MY.UTF-8",
    LC_PAPER = "ms_MY.UTF-8",
    LC_IDENTIFICATION = "ms_MY.UTF-8",
    LC_TELEPHONE = "ms_MY.UTF-8",
    LC_MEASUREMENT = "ms_MY.UTF-8",
    LC_TIME = "ms_MY.UTF-8",
    LC_NUMERIC = "ms_MY.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
enum4linux v0.8.9 (http://labs.portcullis.co.uk/application/enum4linux/)
Copyright (C) 2011 Mark Lowe (mrl@portcullis-security.com)

请看给出的警告信息。

perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

另外,注意LC_ALL = (unset)

解决办法很简单。你所要做的就是设置它。

export LC_ALL=en_US.UTF-8

例如,

kali@kali:~$ export LC_ALL=en_US.UTF-8
kali@kali:~$

问题解决了

kali@kali:~$ enum4linux
enum4linux v0.8.9 (http://labs.portcullis.co.uk/application/enum4linux/)
Copyright (C) 2011 Mark Lowe (mrl@portcullis-security.com)

对于永久解决方案,您可能希望将其添加到.bashrc文件中。