The problem is most likely caused by the fact that LC_CTYPE is somehow, somewhere set to "UTF-8", which is not a valid locale name. So you need to figure out how it happens and delete that incorrect setting.
Python locale error: unsupported locale setting - Stack Overflow
How to fix a locale setting warning from Perl - Stack Overflow
opensuse - Failed to set locale. Fix your system - Unix & Linux Stack Exchange
bash - How not to pass the locale through an ssh connection command - Stack Overflow
Run following commands
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
It will solve this.
Make sure to match the .UTF-8 part to the actual syntax found in the output of locale -a e.g. .utf8 on some systems.
According to this link, it solved by entering this command:
export LC_ALL=C
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
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
- On the older host, set the
LANGenvironment variable in your shell's initialization file. - Modify your environment on the client side, e.g., rather than
ssh hunter2, use the commandLANG=C ssh hunter2. - 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_configfile. (Thanks to this answer. See Bug 1285 for OpenSSH for more.)
That's because your locale in your local machine is set to German, which SSH forwards to and tries to use on the server, but your server does not have it installed.
You've got several options:
Generate the locale. Generate the German locale on the server with
sudo locale-gen de.Stop forwarding locale from the client. Do not forward the locale environment variable from your local machine to the server. You can comment out the
SendEnv LANG LC_*line in the local/etc/ssh/ssh_configfile.Stop accepting locale on the server. Do not accept the locale environment variable from your local machine to the server. You can comment out the
AcceptEnv LANG LC_*line in the remote/etc/ssh/sshd_configfile.Set the server locale to English. Explicitly set the locale to English on the server. As an example, you can add the following lines to your remote
~/.bashrcor~/.profilefiles:export LANGUAGE="en" export LANG="C" export LC_MESSAGES="C"
If you don't have root access to the server, the Stop forwarding locale from the client option might be the best (and only) way to go.
This can happen sometimes on fresh minimal/alternate installs or in other situations. The fix is pretty simple. Try these, in the following order, testing after each to see if the situation is fixed:
1. Reconfigure locales
sudo dpkg-reconfigure locales- if that doesn't work,
2. Reinstall locale language-pack
sudo apt-get --reinstall install language-pack-de- if that doesn't work,
3. Manually force locale settings (persistent)
sudo update-locale LC_ALL=de_DE.UTF-8 LANG=de_DE.UTF-8
I fixed this with a few steps for some Raspberry Pis that I was sshing to.
- I commented out
en_GB.UTF-8in/etc/locale.genand uncommenteden_US.UTF-8. - I added the lines
LC_CTYPE=en_US.UTF-8andLC_ALL=en_US.UTF-8to/etc/default/locale. You may need to add more lines like this such asLC_MESSAGES=en_US.UTF-8. - I ran
export LC_ALL=en_US.UTF-8. - Finally, I ran
sudo locale-gen.
If you run locale after these steps you shouldn't see any warnings and you should see en_US.UTF-8 for all of the fields except maybe LANG and LANGUAGE. You can change these manually with export LANG=en_US.UTF-8 and export LANGUAGE=en_US.UTF-8.
As commented here:
Ah, well that explains it. SSH forwards your locale along with the connection. So your Mac is asking for a locale which is not available on your Linux box.
Either change your Mac locale to something consistent or change your Mac SSH settings to not forward locale: https://stackoverflow.com/questions/29609371/how-do-not-pass-locale-through-ssh
It sounds like your SSH client is configured to forward the locale settings. You can prevent this by altering your configuration (the global file is typically /etc/ssh/ssh_config):
# comment out / remove the following line
SendEnv LANG LC_*
Alternatively you can change the configuration of the server, by editing /etc/ssh/sshd_config on the remote machine (note the d in sshd_config):
# comment out / remove the following line
AcceptEnv LANG LC_*
As already explained in other answers, the client will send all environment variables specified via SendEnv in /etc/ssh/ssh_config. You can also force ssh to not send already defined variable names, using your user's configuration.
From OpenSSH man page:
It is possible to clear previously set SendEnv variable names by prefixing patterns with -. The default is not to send any environment variables.
So, to prevent sending your locale, you can put the following into your ~/.ssh/config:
SendEnv -LC_* -LANG*
The root cause is: your environment variable LC_ALL is missing or invalid somehow
Short answer-
just run the following command:
$ export LC_ALL=C
If you keep getting the error in new terminal windows, add it at the bottom of your .bashrc file.
Long answer-
Here is my locale settings:
$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C
Python2.7
$ uname -a
Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux
$ python --version
Python 2.7.9
$ pip --version
pip 8.1.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
$ unset LC_ALL
$ pip install virtualenv
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main
locale.setlocale(locale.LC_ALL, '')
File "/usr/lib/python2.7/locale.py", line 579, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
$ export LC_ALL=C
$ pip install virtualenv
Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.7/dist-packages
Run the following command (it will work):
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
On the server you ssh from do you have a locale set via an environment variable? In looking at my CentOS 6 installation, the only locale that I can find supported is identified as en_US.utf8 (discovered using locale -a command). Could this be the problem?
In my testing, when I set the LC_ALL environment variable to en_US.UTF-8, ssh'd to the server, the output of my locale command was set to POSIX in my case. This the same as when I have NOT set (i.e. unset) the LC_ALL variable before ssh'ing.
When I set my LC_ALL variable to en_US.utf8 or en_US.utf-8, ssh'd to my CentOS 6 box, the output of the locale was the same as what was set on the source box.
Notice I used no caps for UTF also.
Solved this by disabling "Set locale environment variables on startup" in Terminal Settings > Advanced as per this screenshot.

NOTE: If you use iTerm2 you can disable the "Set locale variables automatically" option in Preferences > Profiles > Terminal
Is specifying the user-preferred locale configurations in ~/.profile appropriate for your needs?
Also, to save you the annoyance, stop forwarding locale from your client (/etc/ssh/ssh_config, comment out SendEnv LANG...) and stop accepting on the server (/etc/ssh/sshd_config)..
Or, if you prefer, you can set a ~/.ssh/environment file with the options you want. You'll have to enable PermitUserEnvironment on the server's /etc/ssh/sshd_config file.
Ok, I figured it out. Someone hard coded the LC_ALL and LANG variables in /etc/profile, so everything else was just ignored. After removing these, the locale now gets set according to the environment transmitted by ssh.
Debian ships locales in source form. They need to be compiled explicitly. The reason for this is that compiled locales use a lot more disk space, but most people only use a few of them.
Run dpkg-reconfigure locales as root, select the locales you want in the list (with your settings, you need en_GB and en_US.UTF-8 — I recommend selecting en_US and en_GB.UTF-8 as well) then press <OK>.
Alternatively, edit /etc/locale.gen, uncomment the lines for the locales you want, and run locale-gen as root.
(Note: on Ubuntu, this works differently: run locale-gen with the locales you want to generate as arguments, e.g. sudo locale-gen en_GB en_US en_GB.UTF-8 en_US.UTF-8.)
Alternatively, Debian now has a package locales-all which you can install instead of locales. It has all the locales pre-generated. The downside is that they use up more disk space (112MB vs 16MB).
The top-rated solution didn't help in my case, so I used this one:
export LC_ALL="en_US.UTF-8"
sudo dpkg-reconfigure locales
After that, I logged out and logged in and error was missing.