星期三, 2月 19, 2014

perl warning for setting locale failed

Can't set locale; make sure $LC_* and $LANG are correct!
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US:en",
LC_ALL = (unset),
LC_TIME = "zh_TW.utf8",
LC_MONETARY = "zh_TW.utf8",
LC_MEASUREMENT = "zh_TW.utf8",
LC_NUMERIC = "zh_TW.utf8",
LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory
上面這情形發生在透過 ssh 連到遠端機器執行與 perl 相關的程式時所發生的。
古哥說下面這地方有解法
http://stackoverflow.com/questions/2499794/how-can-i-fix-a-locale-warning-from-perl

原因在於 /etc/ssh/sshd_config 中有一行設定
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
這表示 ssh client 可以把它的 locale 環境變數傳給 ssh server。
但若 ssh server 中沒有安裝該 locale,就會出現上面這樣的訊息。

所以解法有幾個:
從 server 端解:
1. 安裝該 locale
$ sudo dpkg-reconfigure locales

2. ssh server 不要接收從 ssh client 傳來的 locale 環境變數
 # Allow client to pass locale environment variables
 # AcceptEnv LANG LC_*
從 client 解:
執行 ssh 時,強制設定 LANG 的環境變數為 C
$ LANG=C ssh user@remote_server

1 則留言:

Michael Leung 提到...

You are a hardcored server admin!