您当前的位置:首页 > 计算机 > 编程开发 > Perl

解决 perl: warning: Setting locale failed.

时间:10-29来源:作者:点击数:

使用 Ubuntu 主机远程 PVE 服务器执行命令时报错:

# qm list
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_ADDRESS = "zh_CN.UTF-8",
    LC_NAME = "zh_CN.UTF-8",
    LC_MONETARY = "zh_CN.UTF-8",
    LC_PAPER = "zh_CN.UTF-8",
    LC_IDENTIFICATION = "zh_CN.UTF-8",
    LC_TELEPHONE = "zh_CN.UTF-8",
    LC_MEASUREMENT = "zh_CN.UTF-8",
    LC_TIME = "zh_CN.UTF-8",
    LC_NUMERIC = "zh_CN.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").

查看字符集配置发现有报错:

# locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=

经过分析错误为 LC_ALL 没设置值,LC_CTYPELC_MESSAGES 的值 zh_CN.UTF-8 系统未安装。

远程主机默认仅支持 en_US.UTF-8 ,而我的客户端默认配置为 zh_CN.UTF-8 ,结果远程时服务端继承了客户端配置,导致字符集报错。

此时无需在远程做任何配置,只需断开远程连接,将下面一行配置写入我的 Ubuntu 主机中的 ~./bashrc 即可:

export LC_ALL=C

原理

在设定主机 locale 时存在一个优先级,可总结为 LC_ALL > LC_* >LANG ,可以说 LC_ALL最上级设定或者强制设定,而 LANG 是默认设定值。

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门