Ubuntu linux 的中文終端設定

在Ubuntu 12.04 及Ubuntu 14.04 使用Terminal(黑白畫面,下指令的畫面)登入主機 要顯示中文,尤其是你想透過 putty 之類的遠端程式顯示或編輯中文(pietty好像比較好用)。

環境:Ubuntu Server LTS 14.0.4(12試過也行)
症狀:Terminal 沒有中文,putty登入亦同
參考解法:使用zh_TW(.UTF-8)參數設定中文語系檔



法1:
1. /var/lib/locales/supported.d/local
+zh_TW.UTF-8 UTF-8
zh_TW BIG5
en_US.UTF-8 UTF-8

2.重新產生locale設定 sudo  locale-gen
(這個指令也行 sudo dpkg-reconfigure locale)

3. 修改預設的顯示語系 /etc/default/locale 為 zh_TW.UTF-8
sudo vi(m) /etc/default/locale

如下所示
LANG="zh_TW.UTF-8"
LANGUAGE="zh_TW.UTF-8"
LC_NUMERIC="zh_TW.UTF-8"
LC_TIME="zh_TW.UTF-8"
LC_MONETARY="zh_TW.UTF-8"
LC_PAPER="zh_TW.UTF-8"
LC_NAME="zh_TW.UTF-8"
LC_ADDRESS="zh_TW.UTF-8"
LC_TELEPHONE="zh_TW.UTF-8"
LC_MEASUREMENT="zh_TW.UTF-8"
LC_IDENTIFICATION="zh_TW.UTF-8"

4. 登出再登入就可以看到中文了



法2:
如果不行的話
1. 確認語系: 預設應該如下,也就是英文
locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

2. 把 Ubuntu 的語系改成中文,要將繁體中文使用的語系代碼「zh_TW」代入,指令如下

sudo locale-gen zh_TW
sudo locale-gen zh_TW.UTF-8
sudo dpkg-reconfigure locales
sudo update-locale LANG="zh_TW.UTF-8" LANGUAGE="zh_TW"

3.登出再登入語系的環境變數才會生效
所以,設定完成後,請先登出再登入,再用 locale 指令來看,應該就是zh_TW.UTF-8 了

locale
LANG=zh_TW.UTF-8
LANGUAGE=zh_TW
LC_CTYPE="zh_TW.UTF-8"
LC_NUMERIC="zh_TW.UTF-8"
LC_TIME="zh_TW.UTF-8"
LC_COLLATE="zh_TW.UTF-8"
LC_MONETARY="zh_TW.UTF-8"
LC_MESSAGES="zh_TW.UTF-8"
LC_PAPER="zh_TW.UTF-8"
LC_NAME="zh_TW.UTF-8"
LC_ADDRESS="zh_TW.UTF-8"
LC_TELEPHONE="zh_TW.UTF-8"
LC_MEASUREMENT="zh_TW.UTF-8"
LC_IDENTIFICATION="zh_TW.UTF-8"
LC_ALL=



後記:之後,要再改回英文語系的話,請執行
sudo update-locale LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8"
登出後再登入(重新開機也可以),就會回到英文語系了哩 ! ...

如果遇到類似下方的的錯誤訊息的話,是沒有產生相對語系檔的關係,也可以用之前說的指令來設定
錯誤訊息:
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  

留言

這個網誌中的熱門文章

使用 Excel 計算2個地點之間的直線距離

LINE 儲存的檔案傳到 email 不方便 很不方便 非常不方便 但是有解的筆記

合併列印標籤漏印