26

How to solve this warning being prompted every time I execute Elixir code or enter 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
Rustam Gasanov
  • 15,290
  • 8
  • 59
  • 72

8 Answers8

20

Apparently unset LC_ALL= was the issue, I checked

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

ensuring LC_ALL is missing, to fix it, I executed:

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

this command added LC_ALL to /etc/default/locale file:

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

and error is gone.

Rustam Gasanov
  • 15,290
  • 8
  • 59
  • 72
11

I'm using erlang inside a docker container and the other solutions didn't cut it. The command update-locale may not be available inside a docker ubuntu container, so I've stole some code that installs it from 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
ichigolas
  • 7,595
  • 27
  • 50
  • FWIW, this didn't work for me without also setting the `LANG` environment variable w/ an `ENV` declaration. I didn't realize the existence of the environment variable at runtime was significant. – ollien Feb 26 '23 at 20:16
6

I encountered this when using a docker image. Adding the following line to my Dockerfile solved this:

ENV LANG=C.UTF-8
vee
  • 1,247
  • 16
  • 18
5

This happens when you SSH from your Mac laptop to a Linux server (including a virtual Linux server running on your laptop). SSH forwards the LANG and LC_* environment variables from the local shell to the remote shell, and some of the values used on the Mac are not valid on the Linux server.

The problem can be fixed in various ways, including installing the missing locales on the server. I recommend simply disabling the SSH environment forwarding, either on the server (remove AcceptEnv in /etc/ssh/sshd_config) or on the laptop (remove SendEnv in /etc/ssh/ssh_config).

Read more in How to fix a locale setting warning from Perl?

5

On centOS 7 the following worked for me:

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

Should work for most if not all RHEL distributions. Cheers!

radtek
  • 34,210
  • 11
  • 144
  • 111
3

in the nix-shell this command helped me:

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

ref: https://nixos.wiki/wiki/Locales

nils petersohn
  • 2,317
  • 2
  • 25
  • 27
1

For me setting the locale in my init script /etc/init/my_start_script.conf did the trick

env LC_ALL=en_US.UTF-8 
export LC_ALL
Informatom
  • 103
  • 4
0
sudo dpkg-reconfigure locales

on Ubuntu 18.04.5 LTS did it!

user 1007017
  • 391
  • 2
  • 10