VM 是 运行 latin1 的本机名称编码,这可能会导致 Elixir 出现故障,因为它需要 utf8

the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8

如何解决每次执行Elixir代码或输入iex时提示这个警告?

warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)

$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.utf8
LANGUAGE=en_US:
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04 LTS
Release:        14.04
Codename:       trusty

显然未设置 LC_ALL= 是问题,我检查了

$ cat /etc/default/locale
LANG="en_US.utf8"
LANGUAGE="en_US:"

确保缺少 LC_ALL为了修复它,我执行了:

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

此命令已将 LC_ALL 添加到 /etc/default/locale 文件:

$ cat /etc/default/locale
LANG="en_US.utf8"
LANGUAGE="en_US:"
LC_ALL=en_US.UTF-8

错误消失了。

对我来说,在我的初始化脚本中设置语言环境 /etc/init/my_start_script.conf 成功了

env LC_ALL=en_US.UTF-8 
export LC_ALL

我在 docker 容器中使用 erlang,而其他解决方案并没有解决它。命令 update-locale 在 docker ubuntu 容器中可能不可用,所以我从 https://hub.docker.com/r/voidlock/erlang/~/dockerfile/.

中窃取了一些安装它的代码
apt-get update && apt-get install -y --no-install-recommends locales
export LANG=en_US.UTF-8 \
    && echo $LANG UTF-8 > /etc/locale.gen \
    && locale-gen \
    && update-locale LANG=$LANG

当您从 Mac 笔记本电脑通过 SSH 连接到 Linux 服务器(包括笔记本电脑上的虚拟 Linux 服务器 运行)时,就会发生这种情况。 SSH 将 LANGLC_* 环境变量从本地 shell 转发到远程 shell,Mac 上使用的某些值在 Mac 上无效Linux 服务器。

可以通过多种方式解决该问题,包括在服务器上安装缺少的语言环境。我建议简单地禁用 SSH 环境转发,在服务器上(在 /etc/ssh/sshd_config 中删除 AcceptEnv)或在笔记本电脑上(在 /etc/ssh/ssh_config 中删除 SendEnv)。

How to fix a locale setting warning from Perl?

中阅读更多内容

在 centOS 7 上,以下对我有用:

localedef -c -f UTF-8 -i en_US en_US.UTF-8
export LC_ALL=en_US.UTF-8

即使不是全部,也应该适用于大多数 RHEL 发行版。干杯!

我在使用 docker 图片时遇到了这个问题。将以下行添加到我的 Dockerfile 解决了这个问题:

ENV LANG=C.UTF-8
sudo dpkg-reconfigure locales

在 Ubuntu 18.04.5 LTS 上做到了!

在 nix-shell 这个命令帮助了我:

export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive

参考:https://nixos.wiki/wiki/Locales