How to fix a locale setting warning from Perl
Asked Answered
B

48

839

When I run perl, I get the warning:

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

How do I fix it?

Banian answered 23/3, 2010 at 12:27 Comment(5)
What happened when you checked the locale settings like the error message told you?Vivian
instead of installing the locale, you can also change the locale. On my Ubuntu box, this is done for one user by editing ~/.pam_environmentLawry
On my ODROID-C1 running Ubuntu the issue was indeed the ~/.pam_environment file. Some of the variables were es_US.UTF-8 instead of en_US.UTF-8. Thank you.Intussuscept
I got this on Cygwin\Babun. Only a reinstall of perl fixed it.Aeciospore
If you are here in 2023, it probably means you are SSH:ing into a Raspbian device.Yore
S
553

Your OS doesn't know about en_US.UTF-8.

You didn't mention a specific platform, but I can reproduce your problem:

% uname -a
OSF1 hunter2 V5.1 2650 alpha
% perl -e exit
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

My guess is you used ssh to connect to this older host from a newer desktop machine. It's common for /etc/ssh/sshd_config to contain

AcceptEnv LANG LC_*

which allows clients to propagate the values of those environment variables into new sessions.

The warning gives you a hint about how to squelch it if you don't require the full-up locale:

% env LANG=C perl -e exit
%

or with Bash:

$ LANG=C perl -e exit
$ 

For a permanent fix, choose one of

  1. On the older host, set the LANG environment variable in your shell's initialization file.
  2. Modify your environment on the client side, e.g., rather than ssh hunter2, use the command LANG=C ssh hunter2.
  3. If you have administrator rights, stop ssh from sending the environment variables by commenting out the SendEnv LANG LC_* line in the local /etc/ssh/ssh_config file. (Thanks to this answer. See Bug 1285 for OpenSSH for more.)
Selfless answered 24/3, 2010 at 18:50 Comment(13)
Thanks! I had this error message when connecting with git to my server. After adding de_CH.UTF-8 (was not supported there but used locally) with dpkg-reconfigure locales the message is gone.Tycho
I had this issue for ages,... removing "AcceptEnv LANG LC_*" from sshd_config finally resolved it. Thanks for the hint!Tunicate
@Greg Bacon, Wouldn't there also be cases in which you would want to set the environment variables system wide, for example by creating an /etc/environment file? help.ubuntu.com/community/…Quintonquintuple
@HermannIngjaldsson, at least on Ubuntu (12.10), there was no need to reboot the server (after removing "AcceptEnv LANG LC_*"). I just reloaded ssh config: service ssh reload, which takes a fraction of a second, and doesn't even cause the current ssh session to terminate.Himelman
append 'export LC_ALL=C' then 'source ~/.bashrc' at client system solve the problem.Henryk
Another option for folks who use git and get this error when interacting with a remote is to comment out SendEnv LANG LC_* in /etc/ssh/ssh_config on the client machine.Socalled
or try fix 3.: Add the locales which are typically set by ssh clients in /etc/locale.gen, then run dpkg-reconfigure locales. If you know which locales are affected, this might be the least invasive measure.Welt
commenting out "AcceptEnv LANG LC_*" in sshd_config wiped my bash history on the host :( so think before doing that people!Corsica
Thank you from 2017! Commented sshd_config with no problems... Was very confused where pt-BR locale was coming from on that server!Postobit
Fellow Gentoo users: I followed the advice of commenting out the SendEnv line in /etc/ssh/ssh_config. See also the (polarized) discussion at bugs.gentoo.org/367017 .Hamper
Instead of changing the global ssh config file you can also add SetEnv LANG=C in ~/.ssh/config for the host that complains.Pinhead
I'm confused about fix 1. (editing .bashrc on the host did not work in my case). How is this supposed to work, if the client locale env variables are still forwarded by the ssh client?Moya
You can also alias permanent solution number 2: alias ssh='(){ LANG=C ssh $@ }' in your .zshrcNickinickie
F
611

Here is how to solve it on Mac OS X v10.7 (Lion) or Cygwin (Windows 10):

Add the following lines to your bashrc or bash_profile file on the host machine:

# Setting for the new UTF-8 terminal support in Lion
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

If you are using Z shell (zsh), edit file zshrc:

# Setting for the new UTF-8 terminal support in Lion
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8
Flunky answered 14/9, 2011 at 9:9 Comment(12)
Thanks, I've search a solution for this problem for a long time, and I always thought it's a problem in my Ubuntu server configuration, and it seemed that there was no solution that helped (all that dkpg-reconfigure stuff(Giraud
Because LC_ALL overwrites all other variables, I’d rather set LANG=de_AT.UTF-8 and individual variables like LC_MESSAGES=en_US.UTF-8. If a variable is not set it falls back to LANG. You can also eg. unset LC_CTYPE to force it fall back to LANG.Deluge
Placing those lines in .bashrc didn't work, but bash_profile solved it! I had to create the file.Protactinium
Putting these lines in ~/.bashrc solved it for me... then must reload using source ~/.bashrc... Thnks <3Franci
and i got this on my ubuntu: "sudo: export: command not found "Abject
Where is the bash_profile script located? or where to I put it once I'm in terminal on Mac Mavericks? bashrc, .bashrc. bash_profile, or .bash_profile are not in my home directory. Or am I supposed to edit my remove linux server (running Cent)S)Gunboat
awesome, thanks for this. I encountered this problem inside and ubuntu vm running on mavericks, but because I was sshed in with an OSX terminal this was the fix.Jola
This fixed the problem for Ubuntu 14 as well. I think my remote machine picked up the locate from my desktop when I SSHed and set the wrong locale. Remote is US machine while my desktop is AUDome
Thanks, this worked fine on ZSH and the oh-my-zsh plugin under Mac OS X El Capitan, at the bottom of ~/.zshrc : LC_CTYPE=en_US.UTF-8 LC_ALL=en_US.UTF-8Marva
@Abject If you are connecting to server, it is possible that you do so as 'root' user. You can confirm it by running "echo $USER". If that is the case, you need to skip 'sudo', as you don't need it.Herschel
As bash_profile is only read by bash for login shells, so this solution can fail for a wide variety of reasons (not a login shell, not using bash, maybe its not run from a shell at all). It is better to change the settings in /etc/default/locale, which can be done manually or using update-locale.Transistor
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8)Pet
S
553

Your OS doesn't know about en_US.UTF-8.

You didn't mention a specific platform, but I can reproduce your problem:

% uname -a
OSF1 hunter2 V5.1 2650 alpha
% perl -e exit
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

My guess is you used ssh to connect to this older host from a newer desktop machine. It's common for /etc/ssh/sshd_config to contain

AcceptEnv LANG LC_*

which allows clients to propagate the values of those environment variables into new sessions.

The warning gives you a hint about how to squelch it if you don't require the full-up locale:

% env LANG=C perl -e exit
%

or with Bash:

$ LANG=C perl -e exit
$ 

For a permanent fix, choose one of

  1. On the older host, set the LANG environment variable in your shell's initialization file.
  2. Modify your environment on the client side, e.g., rather than ssh hunter2, use the command LANG=C ssh hunter2.
  3. If you have administrator rights, stop ssh from sending the environment variables by commenting out the SendEnv LANG LC_* line in the local /etc/ssh/ssh_config file. (Thanks to this answer. See Bug 1285 for OpenSSH for more.)
Selfless answered 24/3, 2010 at 18:50 Comment(13)
Thanks! I had this error message when connecting with git to my server. After adding de_CH.UTF-8 (was not supported there but used locally) with dpkg-reconfigure locales the message is gone.Tycho
I had this issue for ages,... removing "AcceptEnv LANG LC_*" from sshd_config finally resolved it. Thanks for the hint!Tunicate
@Greg Bacon, Wouldn't there also be cases in which you would want to set the environment variables system wide, for example by creating an /etc/environment file? help.ubuntu.com/community/…Quintonquintuple
@HermannIngjaldsson, at least on Ubuntu (12.10), there was no need to reboot the server (after removing "AcceptEnv LANG LC_*"). I just reloaded ssh config: service ssh reload, which takes a fraction of a second, and doesn't even cause the current ssh session to terminate.Himelman
append 'export LC_ALL=C' then 'source ~/.bashrc' at client system solve the problem.Henryk
Another option for folks who use git and get this error when interacting with a remote is to comment out SendEnv LANG LC_* in /etc/ssh/ssh_config on the client machine.Socalled
or try fix 3.: Add the locales which are typically set by ssh clients in /etc/locale.gen, then run dpkg-reconfigure locales. If you know which locales are affected, this might be the least invasive measure.Welt
commenting out "AcceptEnv LANG LC_*" in sshd_config wiped my bash history on the host :( so think before doing that people!Corsica
Thank you from 2017! Commented sshd_config with no problems... Was very confused where pt-BR locale was coming from on that server!Postobit
Fellow Gentoo users: I followed the advice of commenting out the SendEnv line in /etc/ssh/ssh_config. See also the (polarized) discussion at bugs.gentoo.org/367017 .Hamper
Instead of changing the global ssh config file you can also add SetEnv LANG=C in ~/.ssh/config for the host that complains.Pinhead
I'm confused about fix 1. (editing .bashrc on the host did not work in my case). How is this supposed to work, if the client locale env variables are still forwarded by the ssh client?Moya
You can also alias permanent solution number 2: alias ssh='(){ LANG=C ssh $@ }' in your .zshrcNickinickie
P
264

If you are creating a rootfs using debootstrap you will need to generate the locales. You can do this by running:

# (optional) enable missing locales
sudo nano /etc/locale.gen

# then regenerate
sudo locale-gen

This tip comes from, https://help.ubuntu.com/community/Xen

Postern answered 15/3, 2012 at 20:28 Comment(8)
locale-gen does not take any arguments (in Debian stable at least). Instead, edit /etc/locale.gen to uncomment the locales you want, then run sudo locale-genSpleenwort
On Debian you may need to do $ echo en_US UTF-8 >> /etc/locale.gen first.Allantois
On Gentoo (at least), locale-gen does not take arguments. It reads from /etc/locale.gen.Hamper
some distributions don't use a configuration file and need the following, sudo locale-gen en_US.UTF-8Postern
@Allantois You should only need to uncomment the line # en_US.UTF-8 UTF-8.Teheran
What is "rootfs"? tmpfs?Baptistery
editing /etc/locale.gen uncommenting da_DK.UTF-8 and run sudo locale.gen did - after quite some time - the job. Thanks ! Newbee!Heldentenor
I think this is also the case when creating an image using rpi-imager and specifying the locale in settingsXerox
S
186

Use:

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

It works for Debian. I don't know why - but locale-gen had not results.

Important! It's a temporary solution. It has to be run for each session.

Strephonn answered 17/3, 2014 at 13:25 Comment(5)
This one worked for me. I just put it into my .bashrc file.Spraddle
Worked for me too. I only had to set the two settings (LANGUAGE and LC_ALL) that appeared unset in the Perl warningsKindness
On Debian, local-gen only processes locales that are uncommented in /etc/local.gen. You may need to do echo en_US UTF-8 >> /etc/locale.gen first.Allantois
LC_CTYPE may be?Froissart
should be LC_CTYPEKeratogenous
U
172

This generally means you haven't properly set up locales on your Linux box.

On Debian or Ubuntu, that means you need to do

$ sudo locale-gen
$ sudo dpkg-reconfigure locales

See also man locale-gen.

Urochrome answered 23/3, 2010 at 12:33 Comment(7)
does not fix the issue hereAlbedo
dpkg-reconfigure locales - fixed the issue for me, debian 7.1Rhebarhee
dpkg-reconfigure locales fails itself with the same perl locale error messages that one is trying to fix in the first place!!!!Burleson
This worked for me in Ubuntu 14.04, although I had to add the missing locale first with sudo locale-gen es_UY.UTF-8Louralourdes
I had to use LANG=C sudo dpkg-reconfigure localesAurelia
@Burleson Only the first time, before it fixes the error. Try again, and it should be fixed.Nutbrown
Works perfectly when using Ubuntu through the Windows OpenSSH client.Haerle
R
101

For macOS & Mac OS X users only

I was getting the same warning while using Git

To resolve this warning Uncheck the Set locale environment variable on startup option and restart your terminal. Below screen shot represents my terminal settings.

enter image description here

Readjustment answered 17/12, 2013 at 6:33 Comment(5)
I tried all the others but this one did it for me. I use iTerm and it has the same character encoding option.Lyricism
Unfortunately this breaks ZSH (tabbing stopped working)Serration
This totally does the trick for Mac OS. By the way, this starting happening to me right after upgraded to macOS Sierra. And this did fix this issue for me.Exportation
this fixed my problem. it started to happen to me, after updating to Mac OS X High Sierra from Sierra.Entryway
Yup. I use iTerm. Wiping problem Mac system settings fixed some Mac crashes, but caused this issue when running Perl on my long-stable CentOS server, connected via Mac / iTerm. Disabling the automatic locale set on connect fixed it. iTerm -> Preferences ->Profiles->Terminal->Environment->Set locale variables automatically. Uncheck this, and restart iTerm.Therein
G
41

It is simple fix in Ubuntu. You have to generate the Locales from scratch, running the following commands from the command line:

sudo locale-gen en_US en_US.UTF-8
sudo dpkg-reconfigure locales

This should create the locales and then re-configure them.

Gwenette answered 31/12, 2014 at 17:40 Comment(1)
This worked fine to me even using pt_BR pt_BR.UTF-8 - Thanks.Industrialist
S
40

Adding the following to /etc/environment fixed the problem for me on Debian and Ubuntu (of course, modify to match the locale you want to use):

LANGUAGE=en_US.UTF-8
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
Spathe answered 26/1, 2014 at 12:9 Comment(2)
.. I got a warning saying setting locale in /etc/environment is deprecated and should instead be set in /etc/default/locale. Both seems to work for now.Spathe
should be LC_CTYPEKeratogenous
T
27

On Debian, after much searching, this did the trick.

First:

sudo apt-get purge locales

Then:

sudo aptitude install locales

And the famous:

sudo dpkg-reconfigure locales

This rids the system of locales, then re-installs locales and downgrades libc6 from 2.19 to 2.13 which is the issue. Then it configures locales again.

Trimerous answered 18/9, 2014 at 5:34 Comment(3)
dpkg-reconfigure locales is all that is needed. sudo if you are a sudo type guy, or do it as root. Then select your locale according to what you have in your shell environment.Seko
dpkg-reconfigure locales SHOULD be all that is needed. After you have tried that 100 times and looked around the internet and that's all you've seen and the problem still won't resolve itself try the above. Then come back and upvote this. :)Trimerous
If your system is hosed to the point where purging and reinstalling a package solves something, you probably have other, more serious problems.Salvia
S
26

I am now using this:

$ cat /etc/environment
...
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8

Then log out of SSH session and log in again.

Old answer:

Only this helped me:

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

$ sudo su

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

# locale-gen en_US.UTF-8
Generating locales...
  en_US.UTF-8... up-to-date
Generation complete.

# dpkg-reconfigure locales
Generating locales...
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  en_CA.UTF-8... done
  en_DK.UTF-8... done
  en_GB.UTF-8... done
  en_HK.UTF-8... done
  en_IE.UTF-8... done
  en_IN.UTF-8... done
  en_NG.UTF-8... done
  en_NZ.UTF-8... done
  en_PH.UTF-8... done
  en_SG.UTF-8... done
  en_US.UTF-8... up-to-date
  en_ZA.UTF-8... done
  en_ZM.UTF-8... done
  en_ZW.UTF-8... done
Generation complete.

# exit

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
Skolnik answered 25/2, 2015 at 16:6 Comment(1)
This worked fine for me on Ubuntu 15.04, thanks a lot.Rearrange
B
22

We will set locales that are not unset after reboot.

First open the Bash file and edit it:

nano .bashrc

Add these lines to the file:

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

Activate the change by reloading Bash:

source ~/.bashrc

Test results:

locale
Banville answered 2/2, 2019 at 0:38 Comment(2)
The only one that works for me, Raspbian and ubuntu server 16.04 :)Bedside
If you are looking for a copy/paste answer, this might work. What exactly works depends on which locales are actually installed. Anyway, this is a duplicate of older answers with essentially the same solution.Salvia
F
19

For Debian users, I have this problem after modifying my locale to change machine's language. This is what I did:

  1. Modify .bashrc:

    export LANG=fr_FR.UTF-8
    export LC_ALL=fr_FR.UTF-8
    
  2. Uncomment line fr_FR.UTF-8 in file /etc/locale.gen -> sudo locale-gen to generate the missing package

  3. sudo update-locale

  4. sudo dpkg-reconfigure locales to configure my locale to fr_FR.UTF-8

  5. Add extra lines to the /etc/default/locale file:

    LANGUAGE=en_US.UTF-8
    LC_ALL=en_US.UTF-8
    LANG=en_US.UTF-8
    LC_TYPE=en_US.UTF-8
    
  6. Reboot my computer and everything works fine

Fucoid answered 10/7, 2019 at 8:38 Comment(1)
Sometimes 5. is the only thing that works. Still kinda puzzled by this behaviour.Piled
S
14

For Ubuntu use this,

#export LANGUAGE=en_US.UTF-8
#export LC_ALL=en_US.UTF-8
#export LANG=en_US.UTF-8
#export LC_TYPE=en_US.UTF-8

It worked for me.

Soothsayer answered 12/4, 2018 at 12:59 Comment(2)
It also worked for me, by removing all content in file /etc/default/locale and putting only the definition of the vars (removing the word export) and restarting the serverAloha
... and not for me. "worked for you" generally is not a good enough criterion. I suggest trying what I post belowGallican
A
14

Debian GNU/Linux 11 (bullseye)

I encountered this issue after creating a brand new VM instance in GCP.

Basically, I have just run the following

$ sudo apt-get update
$ sudo apt-get upgrade

Here I have got the error

error image

perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LC_TERMINAL = "iTerm2",
LANG = "C"
are supported and installed on your system.

Here is how I fixed it.

  • Install the locales first.
$ sudo apt-get install locales
  • Open the locale file (use your favorite editor).
$ sudo nano /etc/default/locale
  • Add the following and save it.
LANGUAGE=en_US.UTF-8
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
  • Run the following.
$ sudo localedef -i en_US -f UTF-8 en_US.UTF-8
  • Restart your terminal.

  • Run the command to test and close it via ctrl + d.

$ perl

Note: I created an instance to just test my solution in order to ensure. Please let me know if it doesn't work for you.

terminal history

I hope it helps you.

Assuming answered 11/5, 2022 at 19:41 Comment(0)
B
13

For Ubuntu Server and Debian:

No need to create exports in bashrc or deal with dpkg-reconfigure.

Just replace the contents of /etc/default/locale with:

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
Brainbrainard answered 5/11, 2021 at 17:36 Comment(2)
Even though this had no effect, through some kind of trail I can't retrace I found the solution for me (askubuntu.com/a/227513/126830): sudo locale-gen "en_US.UTF-8". So until further notice, thank you for posting this :)Ruprecht
Works for me as suggested by @SridharSarnobatRedshank
T
12

If you use Mac OS X v10.10 (Yosemite) or above to connect in your server Linux, you can try these steps.

  1. Keep your file /etc/ssh/sshd-config original

  2. Put on your ~/.bash_profile

    export LANG="en_US"
    export LC_ALL=$LANG.UTF-8
    
  3. Run

    dpkg-reconfigure locales
    

    And select "en_US.UTF-8"

Tonneson answered 15/12, 2015 at 23:33 Comment(0)
W
11
sudo nano /etc/locale.gen

Uncomment the locales you want to use (e.g. en_US.UTF-8 UTF-8):

Then run:

sudo /usr/sbin/locale-gen

Source: Configuring Locales

Weakling answered 16/6, 2014 at 13:46 Comment(1)
The company I work for in USA hosts a git server that has international customers. The GB crowd complained that their git clones over ssh would have problems due to locale differences. This applied on the server fixed this issue for them.Wholesale
F
10

You need to configure locale appropriately in /etc/default/locale, logout, login, and then run the regular commands

root@host:~# echo -e 'LANG=en_US.UTF-8\nLC_ALL=en_US.UTF-8' > /etc/default/locale
root@host:~# exit
local-user@local:~$ ssh root@host
root@host:~# locale-gen en_US.UTF-8
root@host:~# dpkg-reconfigure locales
Figurehead answered 9/4, 2014 at 21:24 Comment(1)
these steps worked for me (Ubuntu server 14.04). the main point was to logout and login again.Recollect
T
10
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory

Solution:

Try this (uk_UA.UTF-8 is my current locale. Write your locale, for example en_US.UTF-8 !)

sudo locale-gen uk_UA.UTF-8

and this.

sudo dpkg-reconfigure locales
Tracy answered 24/2, 2016 at 19:22 Comment(1)
Thank you this solved my problem, after doing this and reinstalling.Slavophile
G
10

For me, I fixed this error by editing the .bashrc file, adding exports. Add after the initial comments.

Add language support.

export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_TYPE=en_US.UTF-8
Glade answered 3/1, 2018 at 17:7 Comment(1)
Using LC_ALL shouldn't be necessary as it is meant for use during debugging. LC_ALL overrides all locale settings.Asomatous
K
9

For anyone connecting to DigitalOcean or some other Cloud hosting provider from the iTerm2.app on macOS v10.13 (High Sierra) and getting this error on some commands:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = "UTF-8",
    LANG = "en_US.UTF-8"
  are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

This fixed the problem for me:

Enter image description here

Kendallkendell answered 25/10, 2017 at 17:52 Comment(1)
Yup was this setting in iterm2! Thanks!Martella
T
7

Adding the correct locale to ~/.bashrc, ~/.bash_profile, /etc/environment and the like will solve the problem, however it is not recommended, as it overrides the settings from /etc/default/locale, which is confusing at best and may lead to the locales not being applied consistently at worst.

Instead, one should edit /etc/default/locale directly, which may look something like this:

LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE=en_US

The change will take effect the next time you log in. You can get the new locale in an existing shell by sourcing /etc/default/locale like this:

$ . /etc/default/locale
Transistor answered 3/3, 2018 at 21:14 Comment(3)
need to restart system after this stepMusty
You can simply comment in the desired locale in "/etc/locale.gen" then run: locale-genSinusitis
This is dubious advice. It's perfectly legitimate for the OS to have a default setting but for individual users to want to override that default. On multi-user servers, the OS might be set to use en_US.utf-8, but individual users from other continents might prefer or even require pt_BR.utf-8, ja_JP.utf-8, fr_BF.utf-8, etc.Salvia
I
7

If this problem occurs while you are connecting via ssh to a remote host then it is possible that the remote system is missing certain locales. I am not going to repeat how to install and configure locales as this has been well explained by other answers already.

As other answers have pointed out, ssh should be passing your local computer's locales to the remote host. For example, if you have Australian locales set (e.g., en_AU.UFT-8), and you are connecting to a newly setup Ubuntu Server which only comes with en_US.UTF-8 then you will receive this warning.

To solve this problem you have several options:

  1. Install the required locales on the remote host such that they match locales configured on your client.

  2. Change the SSH configuration to not pass your clients' environment variables. I would not recommend this.

  3. Override the locale on your remote machine by exporting locale settings from file .bashrc and friends.

Intoxicant answered 27/4, 2018 at 10:12 Comment(0)
S
6

Add missing locales to file .bash_profile:

echo "export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8">>~/.bash_profile

Then source your .bash_profile file:

source ~/.bash_profile
Secern answered 8/11, 2017 at 9:44 Comment(0)
C
6

Source of the problem

I experienced this, logging in from one machine to another via ssh. The remote machine didn’t have the locale files, that I had on my local machine. You can either disable the forwarding of the locale from your local machine to the remote machine (in the file /etc/ssh/sshd_config remove the line AcceptEnv LANG LC_CTYPE …) or install the locale (changing it is not necessary in this case).

Installing

On Fedora, Red Hat Linux, and CentOS I used

sudo dnf install langpacks-de

for the German (de) language packs. I logged out, in, and it worked.

Search for other langpacks with

dnf search langpacks-

Changing/Activating

To list available locales I used

localectl list-locales

And to set a new one

sudo localectl set-locale de_DE.utf8
Calceiform answered 6/2, 2020 at 23:39 Comment(2)
I'm on Mac and don't see AcceptEnv LANG LC_CTYPE in /etc/ssh/sshd_config. Any suggestions? ThxPopover
I found it under /etc/ssh/sshd_config.d/100-macos.conf but commenting it out and restarting, still didn't help.Popover
B
5

I have this issue whenever I run a Perl script, such as enum4linux, on the latest Kali Linux version.

kali@kali:~$ lsb_release -a
No LSB modules are available.
Distributor ID:    Kali
Description:    Kali GNU/Linux Rolling
Release:    2020.3
Codename:    kali-rolling
kali@kali:~$

E.g.,

kali@kali:~$ enum4linux
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_ADDRESS = "ms_MY.UTF-8",
    LC_NAME = "ms_MY.UTF-8",
    LC_MONETARY = "ms_MY.UTF-8",
    LC_PAPER = "ms_MY.UTF-8",
    LC_IDENTIFICATION = "ms_MY.UTF-8",
    LC_TELEPHONE = "ms_MY.UTF-8",
    LC_MEASUREMENT = "ms_MY.UTF-8",
    LC_TIME = "ms_MY.UTF-8",
    LC_NUMERIC = "ms_MY.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
enum4linux v0.8.9 (http://labs.portcullis.co.uk/application/enum4linux/)
Copyright (C) 2011 Mark Lowe ([email protected])

Look at the warning message given.

perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

Also, notice that LC_ALL = (unset)

The solution is simple. All you have to do is to set it.

export LC_ALL=en_US.UTF-8

E.g.,

kali@kali:~$ export LC_ALL=en_US.UTF-8
kali@kali:~$

And problem solved

kali@kali:~$ enum4linux
enum4linux v0.8.9 (http://labs.portcullis.co.uk/application/enum4linux/)
Copyright (C) 2011 Mark Lowe ([email protected])

For a permanent solution, you might want to add it to the .bashrc file.

Breakup answered 13/8, 2020 at 2:33 Comment(0)
E
4

Following the accepted answer:

LANG=C ssh hunter2.

LC_ALL=C ssh hunter2

on the client side did the trick for me.

Erminiaerminie answered 16/2, 2014 at 17:56 Comment(1)
Worked for me on OSX 10.10.3, while only "LANG=C" was not enough. Thanks Alex!Serration
C
4

Another Git-related answer:

The source of the problem might be the Git server. If all else fails, try doing dpkg-reconfigure locales (or whatever is appropriate for your distribution) on the server.

Congregationalism answered 29/4, 2014 at 20:10 Comment(0)
C
4

With zsh ohmyzsh I added this to the .zshrc:

 # You may need to manually set your language environment
 LANGUAGE=en_US.UTF-8
 LANG=en_US.UTF-8
 LC_CTYPE=en_US.UTF-8
 LC_ALL=en_US.UTF-8

By removing the line export LANG=en_US.UTF-8

Reopened a new tab and SSHed in, worked for me :)

Charlyncharm answered 25/12, 2016 at 11:2 Comment(2)
What is "zsh ohmyzsh"?Baptistery
ZSH is a different type of terminal, from the standard one. Oh. My ZSH is meant to improve that same terminal. from website: Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout... ohmyz.shCharlyncharm
B
4

Export the variable

$ export LANGUAGE=en_US.UTF-8
$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LC_CTYPE=en_US.UTF-8

Next run

$ sudo locale-gen
$ sudo dpkg-reconfigure locales 

When you run dpkg-reconfigure locales it asks you to choose the locales, choose en_US.UTF-8 . If you run this by selecting all locales, it will take some time to configure.

Barnaul answered 3/9, 2020 at 6:16 Comment(0)
L
3

In my case, this was the output:

LANGUAGE = (unset),
LC_ALL = (unset),
LC_PAPER = "ro_RO.UTF-8",
LC_ADDRESS = "ro_RO.UTF-8",
....

The solution was:

sudo locale-gen ro_RO.UTF-8
Leprous answered 8/11, 2014 at 19:3 Comment(1)
I also see LANGUAGE = (unset) but don't have the locale-gen commandCoccidioidomycosis
A
3

Add LC_ALL="en_GB.utf8" to /etc/environment and reboot. That's all.

Abbottson answered 13/7, 2015 at 8:24 Comment(0)
M
3

If you don't care about the locale issue, you can set PERL_BADLANG=0. Of course, this could result in incorrect localisation.

Marguritemargy answered 4/10, 2016 at 14:36 Comment(0)
C
3

All the previous answers are wrong. The message is clear - missing locale. The solution is to add the appropriate locale. You do that by editing the /etc/locale.gen file, remove the # sign in front of the locale being reported as missing and then issuing the command:

$ sudo locale-gen

This will actually generate the locales specified in /etc/locale.gen and therefore the message will not be shown.

Culinary answered 10/5, 2017 at 21:27 Comment(1)
This is simply the answer and worked on ancient Debian (6) for me. All the rest are over-complicated and a bit off-track.Sinusitis
E
3

In my case, with Debian 8.6 (Jessie), I had to change settings in:

/etc/ssh/ssh_config` for `#AcceptEnv LANG LC_*

and

sshd_config for #SendEnv LANG LC_*

Then restart the ssh service.

At last, I did:

locale-gen en_US.UTF-8 and dpkg-reconfigure locales

Ettieettinger answered 6/8, 2017 at 8:44 Comment(0)
D
3

In Arch Linux using a UK keyboard and locale, I had the following error:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.utf8"
  • Exporting my locales in /etc/profile didn't fix it.

  • I did however fix this by editing /etc/locale.gen, also enabling the en_US.utf8 locale that perl expected to find, and running local-gen.

(I use pac-manager which uses a whole bunch of perl modules from AUR, so reinstalling perl in my particular case would be a nuisance.)

Due answered 28/11, 2017 at 20:27 Comment(0)
G
3
perl -e exit
sudo localedef -i en_US -f UTF-8 en_DE.UTF-8
#                                   DE = German
# Use your country code en lieu of  DE

# The second "perl" should then not complain any more
perl -e exit

localectl list-locales # Just make sure it is OK
Gallican answered 10/10, 2020 at 22:14 Comment(2)
be aware that after this you might run into: "kwin_xkbcommon: XKB: couldn't find a Compose file for locale "en_DE.UTF-8" on KDE , tbh. Yet perl is quite happy with it.Gallican
Thank you for this post. What is strange (to me) is that simply setting the environment variables in my .bashrc (before running any perl commands involved in my login) did not work. This solution did, so thanks a bunchCoccidioidomycosis
H
2

As always, the devil is in the detail...

On Mac OS X v10.7.5 (Lion), to fix some Django error, in my ~/.bash_profile I've set:

export LANG=en_EN.UTF-8
export LC_COLLATE=$LANG
export LC_CTYPE=$LANG
export LC_MESSAGES=$LANG
export LC_MONETARY=$LANG
export LC_NUMERIC=$LANG
export LC_TIME=$LANG
export LC_ALL=$LANG

And in turn for a long time I got that warning when using Perl.

My bad! As I've realized much later, my system is en_US.UTF-8! I fixed it simply by changing from

export LANG=en_EN.UTF-8

to

export LANG=en_US.UTF-8
Hotpress answered 29/8, 2014 at 12:1 Comment(0)
F
2

I had multiple users using different shells so in my case this solved:

  • Check which shell
    echo $0
  • if bash
    echo "# Setting locale\nLC_CTYPE=en_US.UTF-8\nLC_ALL=en_US.UTF-8" >> .bashrc
  • if zsh
    echo "# Setting locale\nLC_CTYPE=en_US.UTF-8\nLC_ALL=en_US.UTF-8" >> .zshrc
Fonsie answered 2/5, 2022 at 10:27 Comment(0)
D
2

If you are using iTerm2 on MacOS this issue can be solved by unchecking this setting: iTerm2 > Settings > Profiles > Terminal > Set locale variables automatically:

enter image description here

Danseuse answered 16/2, 2023 at 11:14 Comment(0)
U
1

ssh overwrites LC locale variables by default. See /etc/ssh/sshd_config:

AcceptEnv LANG LC_*

So maybe you need to set these variables in your local shell.

Upbeat answered 27/8, 2015 at 14:2 Comment(0)
E
1

For me, on Ubuntu 16.04 (Xenial Xerus) the following worked:

root@host:~#locale-gen en_GB.UTF-8
root@host:~#localectl set-locale LANG=en_GB.UTF-8,LC_ALL=en_GB.UTF-8

Then reboot...

Elvieelvin answered 21/10, 2016 at 20:18 Comment(0)
A
1

Setting the LC_TYPE environment variable to the default locale language "C" will help to suppress this warning.

Run export LC_CTYPE="C" and try to run the perl command.

P.S: You need to set this variable in one of file /etc/environment or file /etc/default/locale for a permanent solution.

Appraisal answered 18/12, 2019 at 5:46 Comment(1)
for csh shell, run the command : setenv LC_CTYPE "C". We can also add the same in ~/.cshrc file and then run the command "source ~/.cshrc" to re-load the variables.Wormeaten
B
1

I had LC_COLLATE=C set on my machine on /etc/locale.conf. I simply deleted that line, so that only LANG=en_US.UTF-8 (or equivalent for you) is set, and get no more problems.

Befog answered 24/11, 2021 at 0:10 Comment(0)
W
0

If you are running a chroot in CentOS, try manually copying /usr/lib/locale to the chroot environment for the account that is having this issue.

Walden answered 19/4, 2014 at 18:21 Comment(2)
Where to should these be copied?Rains
Copy it into the chroot environment of the account that you are having trouble with. In my case (with Plesk) this was to /var/www/vhosts/[domain]/usr/lib/, but you will have to determine this path for your server/account.Walden
S
0

In case someone has a server with Strato and tries to figure this out, check /etc/profile. I was regenerating locales and setting variables for too long before I found out that there are two lines at the end of this file which overwrote my locale settings all the time.

Sleep answered 18/9, 2021 at 11:29 Comment(0)
M
0

Tried those ways on Mac M1 Monterey, but no one works. My quick way to disable that message: Open Terminal -> Preferences -> Advanced tab -> uncheck to Set locale environment variables on startup

Mile answered 6/4, 2022 at 3:13 Comment(0)
O
-4

Try to reinstall:

localess apt-get install --reinstall locales

Read more in How to change the default locale

Ordzhonikidze answered 21/10, 2015 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.