CentOS 8修改系統語言為中文且立即生效


CentOS 8默認安裝時候,如果選成英文,看文檔的時候有可能會費勁。

有的時候需要man或者help的時候,看中文文檔來的快。

locale命令

[root@C8-3 ~]# locale --help
[root@C8-3 ~]# locale --help
Usage: locale [OPTION...] NAME
  or:  locale [OPTION...] [-a|-m]
Get locale-specific information.

 System information:
  -a, --all-locales          Write names of available locales
  -m, --charmaps             Write names of available charmaps

 Modify output format:
  -c, --category-name        Write names of selected categories
  -k, --keyword-name         Write names of selected keywords
  -v, --verbose              Print more information

  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version

For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

locale命令實際顯示的是/etc/locale.conf中設定的內容

[root@C8-3 ~]# cat /etc/locale.conf 
LANG=en_US.utf8
[root@C8-3 ~]# . /etc/locale.conf 
[root@C8-3 ~]# locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

查看系統中已有支持的語言

[root@C8-3 ~]# locale -a
C
C.utf8
en_AG
en_AU
en_AU.utf8
en_BW
en_BW.utf8
en_CA
en_CA.utf8
en_DK
en_DK.utf8
en_GB
en_GB.iso885915
en_GB.utf8
en_HK
en_HK.utf8
en_IE
en_IE@euro
en_IE.utf8
en_IL
en_IN
en_NG
en_NZ
en_NZ.utf8
en_PH
en_PH.utf8
en_SC.utf8
en_SG
en_SG.utf8
en_US
en_US.iso885915
en_US.utf8
en_ZA
en_ZA.utf8
en_ZM
en_ZW
en_ZW.utf8
POSIX

發現沒有中文

安裝中文語言支持擴展包

[root@C8-3 ~]# yum -y install langpacks-zh_CN
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: -1 day, 11:03:52 ago on Thu Nov  5 14:36:43 2020.
Dependencies resolved.
===============================================================================
 Package                 Architecture Version            Repository       Size
===============================================================================
Installing:
 langpacks-zh_CN         noarch       1.0-12.el8         AppStream       9.6 k
Installing weak dependencies:
 glibc-langpack-zh       x86_64       2.28-101.el8       base            2.1 M

Transaction Summary
===============================================================================
Install  2 Packages

Total download size: 2.2 M
Installed size: 15 M
Downloading Packages:
(1/2): langpacks-zh_CN-1.0-12.el8.noarch.rpm   1.1 kB/s | 9.6 kB     00:08    
(2/2): glibc-langpack-zh-2.28-101.el8.x86_64.r 175 kB/s | 2.1 MB     00:12    
-------------------------------------------------------------------------------
Total                                          176 kB/s | 2.2 MB     00:12     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                       1/1 
  Installing       : glibc-langpack-zh-2.28-101.el8.x86_64                 1/2 
  Installing       : langpacks-zh_CN-1.0-12.el8.noarch                     2/2 
  Running scriptlet: langpacks-zh_CN-1.0-12.el8.noarch                     2/2 
  Verifying        : langpacks-zh_CN-1.0-12.el8.noarch                     1/2 
  Verifying        : glibc-langpack-zh-2.28-101.el8.x86_64                 2/2 

Installed:
  langpacks-zh_CN-1.0-12.el8.noarch    glibc-langpack-zh-2.28-101.el8.x86_64   

Complete!

再次查看,發現有中文了

[root@C8-3 ~]# locale -a
C
C.utf8
en_AG
en_AU
en_AU.utf8
en_BW
en_BW.utf8
en_CA
en_CA.utf8
en_DK
en_DK.utf8
en_GB
en_GB.iso885915
en_GB.utf8
en_HK
en_HK.utf8
en_IE
en_IE@euro
en_IE.utf8
en_IL
en_IN
en_NG
en_NZ
en_NZ.utf8
en_PH
en_PH.utf8
en_SC.utf8
en_SG
en_SG.utf8
en_US
en_US.iso885915
en_US.utf8
en_ZA
en_ZA.utf8
en_ZM
en_ZW
en_ZW.utf8
POSIX
zh_CN
zh_CN.gb18030
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.utf8
zh_SG
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.euctw
zh_TW.utf8

使用localectl命令設定系統語言為中文

查看localectl是否存在

[root@C8-3 ~]# type localectl
localectl is hashed (/usr/bin/localectl)

輸入localectl命令並用tab鍵補全,查看可以跟的參數

[root@C8-3 ~]# localectl 
list-keymaps              list-x11-keymap-options   set-x11-keymap
list-locales              list-x11-keymap-variants  status
list-x11-keymap-layouts   set-keymap                
list-x11-keymap-models    set-locale                

選擇set-locale參數 ,tab補全 ,使用LANG=參數查看當前系統支持的語言,相當於locale -a。

[root@C8-3 ~]# localectl set-locale LANG=
C.utf8           en_GB.utf8       en_PH.utf8       zh_CN
en_AG            en_HK            en_SC.utf8       zh_CN.gb18030
en_AU            en_HK.utf8       en_SG            zh_CN.gbk
en_AU.utf8       en_IE            en_SG.utf8       zh_CN.utf8
en_BW            en_IE@euro       en_US            zh_HK
en_BW.utf8       en_IE.utf8       en_US.iso885915  zh_HK.utf8
en_CA            en_IL            en_US.utf8       zh_SG
en_CA.utf8       en_IN            en_ZA            zh_SG.gbk
en_DK            en_NG            en_ZA.utf8       zh_SG.utf8
en_DK.utf8       en_NZ            en_ZM            zh_TW
en_GB            en_NZ.utf8       en_ZW            zh_TW.euctw
en_GB.iso885915  en_PH            en_ZW.utf8       zh_TW.utf8

設定系統語言為zh_CN.utf8

[root@C8-3 ~]# localectl set-locale LANG=zh_CN.utf8 

查看當前系統語言

[root@C8-3 ~]# locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

發現並沒有生效!

[root@C8-3 ~]# type locale
locale is hashed (/usr/bin/locale)

因為重啟才會重新加載配置文件

不重啟馬上生效的辦法

手動加載配置文件,使配置文件被加載到內存中去

[root@C8-3 ~]# . /etc/locale.conf 
[root@C8-3 ~]# type locale
locale 已被錄入哈希表 (/usr/bin/locale)

雖然查看幫助使用中文比較方便,但鑒於所有命令都是英文的,我們還是要習慣於看英文的幫助文檔,遇到看不懂的地方再使用此方法修改系統語言。系統語言為全局變量,改完記得再改回去


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM