Ubuntu下设置中文locale

一般VPS刚开通不没有装中文的locale,通常会报这样的错误。

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "zh_CN.utf8"
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.查看当前系统语言环境

locale

2.查看系统内安装的locale

root@ubuntu-vps:~# 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
POSIX

3.安装zh_CN.utf8

root@ubuntu-vps:~# cd /usr/share/locales
root@ubuntu-vps:/usr/share/locales# ls
install-language-pack remove-language-pack
root@ubuntu-vps:/usr/share/locales# ./install-language-pack zh_CN
Generating locales…
zh_CN.UTF-8… done
Generation complete.
dpkg-trigger: dpkg-trigger 必须从维护者脚本中调用(或者通过 –by-package 选项)

4.验证locale安装是否成功

root@ubuntu-vps:/usr/share/locales# locale
LANG=zh_CN.utf8
LC_CTYPE="zh_CN.utf8"
LC_NUMERIC="zh_CN.utf8"
LC_TIME="zh_CN.utf8"
LC_COLLATE="zh_CN.utf8"
LC_MONETARY="zh_CN.utf8"
LC_MESSAGES="zh_CN.utf8"
LC_PAPER="zh_CN.utf8"
LC_NAME="zh_CN.utf8"
LC_ADDRESS="zh_CN.utf8"
LC_TELEPHONE="zh_CN.utf8"
LC_MEASUREMENT="zh_CN.utf8"
LC_IDENTIFICATION="zh_CN.utf8"
LC_ALL=