Software engineering notes

Linux Locale

指令

查詢目前的語系設定:

$ 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_TW.UTF-8
LANGUAGE=
LC_CTYPE="zh_TW.UTF-8"
(...略...)
LC_MEASUREMENT="zh_TW.UTF-8"
LC_IDENTIFICATION="zh_TW.UTF-8"
LC_ALL=

查詢已安裝的語系:

$ 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

Error: No such file or directory

locale: Cannot set LC_CTYPE to default locale: No such file or directory

解決方法:

sudo locale-gen --lang zh_TW.UTF-8
Generating locales...
  zh_TW.UTF-8... done
  Generation complete.

再執行locale指令就會正常了

參考來源:

http://120.105.184.250/peiyuli/network-2/shell-scripts.htm

Error: cannot change locale

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)

解決方法, 2選1

在 .bashrc 加上

export LANG=en_US.utf-8
export LC_ALL=en_US.utf-8

或在 /etc/environment 加上

LANG=en_US.utf-8
LC_ALL=en_US.utf-8