macos 在 OS X Lion 中,LANG 未设置为 UTF-8,如何解决?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7165108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:20:18  来源:igfitidea点击:

In OS X Lion, LANG is not set to UTF-8, how to fix it?

macosencodingutf-8terminal

提问by mamcx

I try to setup postgress in OS X Lion, and find that is not correctly setup the LOCALE environment var.

我尝试在 OS X Lion 中设置 postgress,发现没有正确设置 LOCALE 环境变量。

This is what is set:

这是设置的:

LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

I expect something with UTF-8. This is a clean OS X Lion setup, with spanish language. I don't move anything.

我期待 UTF-8 的东西。这是一个干净的 OS X Lion 设置,使用西班牙语。我什么都不动。

I don't know how setup it to UTF-8.

我不知道如何将其设置为 UTF-8。

In the terminal settings, is check UTF-8 and set LOCALE in open, despite that don't work.

在终端设置中,检查 UTF-8 并将 LOCALE 设置为打开,尽管这不起作用。

回答by wormintrude

I noticed the exact same issue when logging onto servers running Red Hat from an OSX Lion machine.

从 OSX Lion 机器登录运行 Red Hat 的服务器时,我注意到完全相同的问题。

Try adding or editing the ~/.profilefile for it to correctly export your locale settings upon initiating a new session.

尝试~/.profile为其添加或编辑文件以在启动新会话时正确导出您的区域设置。

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

These two lines added to the file should suffice to set the locale [replace en_USfor your desired locale, and check beforehand that it is indeed installed on your system (locale -a)].

添加到文件中的这两行应该足以设置语言环境 [替换en_US为您想要的语言环境,并事先检查它是否确实安装在您的系统上 ( locale -a)]。

After that, you can start a new session and check using locale:

之后,您可以开始一个新会话并使用locale以下命令进行检查:

$ locale

The following should be the output:

以下应该是输出:

LANG="en_US.UTF-8"  
LC_COLLATE="en_US.UTF-8"  
LC_CTYPE="en_US.UTF-8"  
LC_MESSAGES="en_US.UTF-8"  
LC_MONETARY="en_US.UTF-8"  
LC_NUMERIC="en_US.UTF-8"  
LC_TIME="en_US.UTF-8"  
LC_ALL="en_US.UTF-8"  

回答by FredericK

I recently had the same issue on OS X Sierra with bash shell, and thanks to answers above I only had to edit the file

我最近在使用 bash shell 的 OS X Sierra 上遇到了同样的问题,感谢上面的答案,我只需要编辑文件

~/.bash_profile 

and append those lines

并附加这些行

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

回答by Marcel Kraan

This is a headbreaker for a long time. I see now it's OSX.. i change it system-wide and it works perfect

长期以来,这是一个令人头疼的问题。我现在看到它是 OSX .. 我在系统范围内更改它并且它运行完美

When i add this the LANG in Centos6 and Fedora is also my preferred LANG. You can also "uncheck" export or set locale in terminal settings (OSX) /etc/profile

当我添加这个时,Centos6 和 Fedora 中的 LANG 也是我首选的 LANG。您还可以在终端设置 (OSX) /etc/profile 中“取消选中”导出或设置区域设置

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

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

回答by Milland

if you have zshinstalled you can also update ~/.zprofilewith

如果你有zsh的安装还可以更新~/.zprofile

if [[ -z "$LC_ALL" ]]; then
  export LC_ALL='en_US.UTF-8'
fi

and check the output using the localecmd as show above

并使用localecmd检查输出,如上所示

? locale                                                                                                                                           
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

回答by Jayprakash Dubey

I had this issue with MacOS High Sierria.

我在 MacOS High Sierra 上遇到了这个问题。

Screenshot 1

截图 1

You can set up localeas well as languageto UTF-8 formatusing below command :

您可以设置语言环境以及语言UTF-8格式使用下面的命令:

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

Screenshot 2

截图 2

Now in order to check whether locale environment is updated use below command :

现在为了检查语言环境是否更新,请使用以下命令:

Locale

Screenshot 3

截图 3