I have the exact question as this but there's no solution. I tried but it doesn't work

How do I fix my locale issue?

$ 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.UTF-8
LANGUAGE=
LC_CTYPE=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=

$ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
C
C.UTF-8
en_US.utf8
POSIX

Is this because of en_US.UTF-8 and en_US.utf8 mismatch?

How to fix?

Open terminal and fire the below command:

export LC_ALL="en_US.UTF-8"

This same problem (LC_CTYPE=UTF-8, which is wrong) can happen when you login over ssh from a Mac to a linux box, and your terminal automatically sets environment variables. There's a checkbox for that. Uncheck it, and you're good to go. In iTerm it's in the profile->Terminal Tab.

  • 1
    in iTerm disable the checkbox "Preferences>Profiles>Default>Terminal>Environment>Set locale variables automatically" – ecerulm Mar 6 at 10:46
  • 1
    -1: While this might work, it's extremely invasive. You also potentially affect the behaviour of your local terminal as well as the behaviour of every host you connect to. While your findings are true, it's a better idea to use the ssh_config to make it not send the LC_* for hosts known to have problems. – Max Ried May 31 at 19:23
  • Can you please add your own answer, extending it with more explanation as to why this potentially affects behaviour of your local terminal, and how to tell ssh_config not to send LC_*. Because you just -1 my answer without real explanation. – raarts Jun 4 at 14:37

I had the similar issue and added the below lines in my /etc/default/locale file:

LC_CTYPE="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
LANG="en_US.UTF-8"

I got this from this post: How do I fix my locale issue?

  • 1
    Well, by doing so you end up with a very messy locale configuration. /etc/environment is not intended for setting locales in Ubuntu; /etc/default/locale is. Also, in case of a desktop you should never, ever set LC_ALL persistently. Your way will make the UIs for controlling language/locale settings on a desktop, such as Language Support, useless. – Gunnar Hjalmarsson Mar 14 '16 at 15:31

only with this work for me

sudo dpkg-reconfigure locales
sudo locale-gen

The output from the locale command indicates that you have this incorrect line in your environment:

LC_CTYPE="UTF-8"

("UTF-8" is not a valid locale name.)

It typically comes from /etc/default/locale. Please remove that line, if it's there, and relogin.

If it does not come from there, it can come from your shell configuration, or if you're logged in remotely via SSH, from the configuration of the client machine.

  • Do I change LC_CTYPE to utf8 ? – Lucas Mar 25 '15 at 13:11
  • @Lucas: No, that would be just as bad. Since LANG is set, you can simply remove the whole line which begins with LC_CTYPE. – Gunnar Hjalmarsson Mar 25 '15 at 20:41
  • If you want to set LC_TYPE, you should also set it to "en_US.UTF-8". – Ael Ombreglace Oct 10 '15 at 6:16
  • If it comes from the configuration of the client machine, you can add the locale on the server with dpkg-reconfigure locales. – Paul Rougieux Apr 24 at 20:11

The /etc/default/locale file can have additional (but unnecessary) lines: Example file can look like this:

#  File generated by update-locale
LANG=en_US.UTF-8
LANGUAGE="en_IN:en

To sort out and successfully generate and reconfigure locales, remove or comment out all lines from this file except:

LANG=en_US.UTF-8

The file should finally look like:

#  File generated by update-locale
LANG=en_US.UTF-8
# LANGUAGE="en_IN:en

After this, run dpkg-reconfigure locales, select en_US.UTF-8 when prompted for selecting the locale, and you should be good to go. You'll receive a Generation complete. message when the process is complete.

This commands saved my life

sudo echo "LC_ALL=en_US.UTF-8" >> /etc/environment
sudo echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
sudo echo "LANG=en_US.UTF-8" > /etc/locale.conf
sudo locale-gen en_US.UTF-8
  • 1
    Files are opened before sudo. The redirects won't work unless you were already root. – Martin Thornton Mar 18 at 22:11
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
  • I was running a near-clean Vultr instance with issues as in the question, looked into the environment vars and everything looked alright. However, sudo dpkg-reconfigure locales did something that must have been missing. My ssh sessions are now OK. Thanks! – Jonas Aug 20 at 18:25

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.