1>查看当前语言环境
$ echo $LANG
en_US.UTF-8
2> 查看当前系统是否有中文语言包
$ echo $LANG
en_US.UTF-8
$ locale -a
C
C.UTF-8
en_US.utf8
POSIX
3> 如果没有en_US.utf8,需要安装中文语言包
$ sudo apt-get install language-pack-zh-hans
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
language-pack-zh-hans-base
The following NEW packages will be installed:
language-pack-zh-hans language-pack-zh-hans-base
0 upgraded, 2 newly installed, 0 to remove and 22 not upgraded.
Need to get 1,694 kB of archives.
After this operation, 6,726 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 language-pack-zh-hans-base all 1:18.04+20180712 [1,692 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 language-pack-zh-hans all 1:18.04+20180712 [1,948 B]
Fetched 1,694 kB in 29s (59.1 kB/s)
Selecting previously unselected package language-pack-zh-hans-base.
(Reading database ... 40847 files and directories currently installed.)
Preparing to unpack .../language-pack-zh-hans-base_1%3a18.04+20180712_all.deb ...
Unpacking language-pack-zh-hans-base (1:18.04+20180712) ...
Selecting previously unselected package language-pack-zh-hans.
Preparing to unpack .../language-pack-zh-hans_1%3a18.04+20180712_all.deb ...
Unpacking language-pack-zh-hans (1:18.04+20180712) ...
Setting up language-pack-zh-hans (1:18.04+20180712) ...
Setting up language-pack-zh-hans-base (1:18.04+20180712) ...
Generating locales (this might take a while)...
zh_CN.UTF-8... done
zh_SG.UTF-8... done
Generation complete.
4> 再次查看是否有中文语言包
$ locale -a
C
C.UTF-8
en_US.utf8
POSIX
zh_CN.utf8
zh_SG.utf8
5> 修改系统环境变量
由于我只需要给某个用户的环境变量,不需要全局,所以修改特定用户的bashrc即可
加入下面这一行:
LANG="zh_CN.utf8"
$ vim ~/.bashrc
...
94 # enable programmable completion features (you don't need to enable
95 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
96 # sources /etc/bash.bashrc).
97 #if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
98 # . /etc/bash_completion
99 #fi
100
101 LANG="zh_CN.utf8" # 加在最下面就行
# 执行source命令,使配置文件生效
$ source ~/.bashrc
6> 测试
登陆该用户,已经是中文
root@Dabenstone:~# mkdir ihome
root@Dabenstone:~# cd ihome/
root@Dabenstone:~/ihome# git init
已初始化空的 Git 仓库于 /root/ihome/.git/
root@Dabenstone:~/ihome#
root@Dabenstone:~/ihome#
网友评论