Ubuntu系统安装中文UTF-8支持

第一步,安装中文包:

apt-get install language-pack-zh-hant language-pack-zh-hans

第二步,配置相关环境变量:

vi /etc/environment

在文件中增加语言和编码的设置:

LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"

我的配置文件显示如下:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
LANG="zh_CN.UTF-8"
UNZIP="-O CP936"
ZIPINFO="-O CP936"

第三步,重新设置本地配置:

dpkg-reconfigure locales

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=