Linux locale issue

wmlm發表於2016-04-06

案例1:
debian下安裝程式時,有時候會因為本地設定沒有設定好,Per會給出下面的錯誤提示:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "zh_CN.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
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

要解決這個問題,其實很簡單,只要執行下面幾條命令,一切都會OK

debian:~# apt-get install locales
debian:~# dpkg-reconfigure locales
debian:~# locale

一切都會OK? 不一定,看下面的帖子。

--------------------------------------------------------------------------------------------------------------

 

http : // askubuntu.com/questions/162391/how-do-i-fix-my-locale-issue

 

I am getting this message every time I do something like starting or stopping a service.

perl: warning: Setting locale failed.  

perl: warning: Please check that your locale settings:  

        LANGUAGE = "en_US:en",  

        LC_ALL = (unset),  

        LC_MESSAGES = "en_US.UTF-8",  

        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_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  

(Reading database ... 21173 files and directories currently installed.) 

Removing bind9 ... 

 * Stopping domain name service... bind9                                        [ OK ]

Processing triggers for man-db ...  

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  

How do I fix this error ?

通用的第一招:

First run locale to list what locales currently defined for the current user account:

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

Then generate the missing locale and reconfigure locales to take notice:

$ sudo locale-gen "en_US.UTF-8"
Generating locales...
  en_US.UTF-8... done
Generation complete.
$ sudo dpkg-reconfigure locales
Generating locales...
  en_US.UTF-8... up-to-date
Generation complete.

Now you will not see any errors anymore!

如果第一招不靈:

比如Umair 反饋說: did not work for me – Umair

 

 Ivan Buttinoni又支了一招

@UmairAyub may be you have more than one unknow locale, try this: for y in $(locale | cut -d '=' -f 2| sort |uniq );do locale-gen $y; done It will generate a locale for each definition you have – Ivan Buttinoni 

另外,設定環境變數也可以解決這個問題:

putting to the file /etc/environment:

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8

 

或者更新到/etc/default/locale

sh -c "echo -e 'LANG=en_US.UTF-8\nLC_ALL=en_US.UTF-8' > /etc/default/locale"

 

如果是在遠端連線時報的這個錯誤,可以使用下面的方法:

This is a common problem if you are connecting remotely, so the solution is to not forward your locale. Edit /etc/ssh/ssh_config and comment out SendEnv LANG LC_* line.

 

On OSX (connecting to ubuntu) it's at /etc/ssh_config

One-liner to do this: sed -e '/SendEnv/ s/^#*/#/' -i /etc/ssh/ssh_config (useful for server provisioning) 

 

update-locale命令做了什麼?

here is a command for that:

sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8

It updates /etc/default/locale with provided values.

 

dpkg-reconfigure locales可能什麼返回都沒有,需要安裝語言包:

What worked for me on 12.10 was this:

apt-get install language-pack-en-base  

This was after dpkg-reconfigure locales produced no results.

 

其他還有很多補充,比如使用KDE時怎麼辦.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/271063/viewspace-2075885/,如需轉載,請註明出處,否則將追究法律責任。

相關文章