馆子737 / linux / 解决 perl: warning: Setting locale fail...

0 0

   

解决 perl: warning: Setting locale failed. | aaron67's log

2014-04-28  馆子737

在Ubuntu Server 12.04上执行apt-get install命令时,报如下warning

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "zh_CN:zh",
        LC_ALL = (unset),
        LC_TIME = "zh_CN",
        LC_MONETARY = "zh_CN",
        LC_ADDRESS = "zh_CN",
        LC_TELEPHONE = "zh_CN",
        LC_NAME = "zh_CN",
        LC_MEASUREMENT = "zh_CN",
        LC_IDENTIFICATION = "zh_CN",
        LC_NUMERIC = "zh_CN",
        LC_PAPER = "zh_CN",
        LANG = "zh_CN.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

搜了一下解决办法,参考这篇文章,在家目录下

1
$ vi .bashrc

在文件尾加入

1
export LC_ALL=C

保存后执行

1
$ source .bashrc

问题解决。

为什么这么做?

看了这篇文章了解了下locale,上面报的warning意思大概可以归纳为

  • LC_ALL变量的值unset
  • LC_CTYPE和LC_MESSAGES的值设置的可能有问题

先将原来添加到.bashrc中的“export LC_ALL=C”删除,重启客户端会话,恢复系统到一开始的状态

su到root查看系统locale设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ su - root
# locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:zh
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC=zh_CN
LC_TIME=zh_CN
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY=zh_CN
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER=zh_CN
LC_NAME=zh_CN
LC_ADDRESS=zh_CN
LC_TELEPHONE=zh_CN
LC_MEASUREMENT=zh_CN
LC_IDENTIFICATION=zh_CN
LC_ALL=

查看系统已安装的locale

1
2
3
4
5
6
7
8
9
10
# locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
C.UTF-8
POSIX
en_US.utf8
zh_CN
zh_CN.gb2312

定位错误为 (1) LC_ALL没设置值,(2) LC_CTYPE和LC_MESSAGES的值zh_CN.UTF-8系统未安装

1、设置LC_ALL的值为zh_CN.UTF-8

1
# vi /etc/default/locale

2、执行

1
2
# cd /usr/share/locales
# ./install-language-pack zh_CN

安装这个locale

问题解决。

正如这篇文章所说,LC_ALL的优先级最高,所以不执行步骤1只执行步骤2就可以解决问题。另外,为了避免locale设置成zh_CN可能带来的稀奇古怪的错误,我直接将/etc/default/locale文件从这样

1
2
3
4
5
6
7
8
9
10
11
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
LC_NUMERIC="zh_CN"
LC_TIME="zh_CN"
LC_MONETARY="zh_CN"
LC_PAPER="zh_CN"
LC_NAME="zh_CN"
LC_ADDRESS="zh_CN"
LC_TELEPHONE="zh_CN"
LC_MEASUREMENT="zh_CN"
LC_IDENTIFICATION="zh_CN"

设置成这样

1
2
3
4
5
6
7
8
9
10
11
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_MONETARY="zh_CN.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"

参 考

http://blog.sina.com.cn/s/blog_49f914ab0100sbsp.html

http://wiki.ubuntu.org.cn/%E4%BF%AE%E6%94%B9locale

0

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。如发现有害或侵权内容,请点击这里 或 拨打24小时举报电话:4000070609 与我们联系。

    猜你喜欢

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多