APT-GET时报错

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").

问题环境是阿里云的ECS,系统是Ubuntu 14.04 server,在使用apt-get安装软件的时候,出现了这种warning。

测试过程,引用的网上内容:

因为安装软件时,都会去执行一个update-locale的命令,用来更新locale 这个命令是一个脚本,用perl写的,可以用whereis update-locale查到,位置在/usr/sbin/update-locale

上述报错并不是因为update-locale命令而引起,update-locale这段脚本没有问题,而是因为perl 可以使用以下命令测试:

perl -e exit

真正的原因是perl为系统使用zh_CN.UTF-8,但系统不知道zh_CN.UTF-8是什么东西

解决方法

apt-get install language-pack-zh-hans

安装一个中文语言,系统就知道zh_CN.UTF-8了,这个时候用perl就不会报错了