I am getting this message every time I do something like starting or stopping a service.

perl: warning: Setting locale failed.   
perl: warning: Please check that your locale settings:   
        LANGUAGE = "en_US:en",   
        LC_ALL = (unset),   
        LC_MESSAGES = "en_US.UTF-8",   
        LANG = "en_US.UTF-8"   
    are supported and installed on your system.   
perl: warning: Falling back to the standard locale ("C").   
locale: Cannot set LC_CTYPE to default locale: No such file or directory   
locale: Cannot set LC_MESSAGES to default locale: No such file or directory   
locale: Cannot set LC_ALL to default locale: No such file or directory   
(Reading database ... 21173 files and directories currently installed.)  
Removing bind9 ...  
 * Stopping domain name service... bind9                                        [ OK ]
Processing triggers for man-db ...   
locale: Cannot set LC_CTYPE to default locale: No such file or directory   
locale: Cannot set LC_MESSAGES to default locale: No such file or directory   
locale: Cannot set LC_ALL to default locale: No such file or directory   

How do I fix this error ?

19 Answers 19

up vote 482 down vote accepted

First run locale to list what locales currently defined for the current user account:

$ locale
LANG=C
LANGUAGE=
LC_CTYPE=fi_FI.UTF-8
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE=fi_FI.UTF-8
LC_MONETARY="C"
LC_MESSAGES=fi_FI.UTF-8
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=

Then generate the missing locale and reconfigure locales to take notice:

$ sudo locale-gen "en_US.UTF-8"
Generating locales...
  en_US.UTF-8... done
Generation complete.

$ sudo dpkg-reconfigure locales
Generating locales...
  en_US.UTF-8... up-to-date
Generation complete.

Now you will not see any errors anymore!

  • 201
    did not work for me – Umair Apr 24 '14 at 7:43
  • 3
    This has worked for me on a number of systems. Is there a way to avoid this issue on newly installed systems? – Brylie Christopher Oxley Jan 12 '15 at 17:34
  • 13
    @UmairAyub may be you have more than one unknow locale, try this: for y in $(locale | cut -d '=' -f 2| sort |uniq );do locale-gen $y; done It will generate a locale for each definition you have – Ivan Buttinoni Jun 27 '15 at 18:33
  • 1
    The locale in the locale-gen command should be in double quotes for this to work properly: $ sudo locale-gen "en_US.UTF-8" – Sheharyar Jun 28 '15 at 16:34
  • 4
    @Umair There is a high risk of human error in this problem. Your system is configured to en_GB by default, but you set it up to en_US. You have to manually comment en_GB and uncomment en_US in /etc/locale.gen. See my answer askubuntu.com/a/790373/25388 in the hardware Raspberry Pi 3b and the system Raspbian Jessie. – Léo Léopold Hertz 준영 Jun 22 '16 at 20:27

Nothing suggested above worked in my case (Ubuntu Server 12.04LTS). What finally helped was putting to the file /etc/environment:

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

For some reason it was missing. The outputs for locale and other commands appeared like the variables were properly defined. In other words don't take for granted all the basic stuff is declared where it should be declared.

  • 110
    Yes, none other worked except this one, perhaps due to updated version. But I rather prefer to put this in /etc/default/locale. – Naveed Feb 22 '13 at 20:18
  • 24
    Updated /etc/default/locale and no more warnings. Thanks – ohho Feb 26 '13 at 7:00
  • 6
    Yep, the others didn't work for me. This one did. Here is the one-liner I used for unattended updating of this. sudo sh -c "echo 'LC_ALL=en_US.UTF-8\nLANG=en_US.UTF-8' >> /etc/environment" – dman Mar 22 '14 at 6:01
  • 12
    @user163207 your solution is incorrect because it appends (instead of overwriting), it's not the recommended file, and echo needs to be run with the interpretation of backslash escapes enabled. This is the same as yours but with the aforementioned fixed: sh -c "echo -e 'LANG=en_US.UTF-8\nLC_ALL=en_US.UTF-8' > /etc/default/locale" – glarrain Apr 9 '14 at 21:22
  • 13
    DON'T FORGET TO LOGPUT AND RE-LOGIN! – S.M.Mousavi Nov 16 '15 at 18:05

They should disappear after issuing:

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

dpkg-reconfigure reconfigures packages after they have already been installed. Pass it the names of a package or packages to reconfigure. It will ask configuration questions, much like when the package was first installed.

  • 9
    I am glad my troubles a year ago helped you get this fixed ;) – Rinzwind Jul 11 '12 at 14:34
  • 1
    Shouldn't this locale be generated by default? I mean en, en_AU, en_CA, en_GB are present by default but not en_US? – Daniel Serodio Aug 15 '12 at 16:05
  • @Rinzwind Thanks a lot for your effort! I do apologize; I should have worded my question better. What I meant to ask is: Why is it necessary to reconfigure the locales package after generating new locales? Seems to me like the locales work even without dpkg-reconfigure. – Victor Nov 18 '12 at 11:49
  • Using Ubuntu 14.04, in a Docker container, so nothing was being set. Django's makemessage needs this. This worked perfectly! thanks. – Justin Aug 11 '14 at 18:05
  • 1
    I realize that raspbian is out of scope here, but I thought I'd mention that I had to logout and login before LC_ALL was properly set. – MatrixManAtYrService Dec 29 '17 at 18:27

Just add the following to your .bashrc file (assuming you're using bash)

export LC_ALL="en_US.UTF-8"
  • 2
    This sweet fix worked for me on my Amazon-EC2 image (Was running their default RHEL AMI) Thanks so much! :) – gideon Dec 1 '12 at 15:07
  • This one worked for me with my digitalocean's Ubuntu 12.04 image. – Inan Sep 25 '13 at 11:49
  • 2
    this fixed my problem. I have to ask a question: how come the LC_ALL was not set by the locale-gen command as other answers said above this one ? – alexserver Sep 21 '15 at 18:35
  • Weird, all solution above didn't work for me but this one did! After exporting LC_ALL I could finally use sudo dpkg-reconfigure locales. – sobi3ch Nov 18 '15 at 11:56
  • finally after trying a lot of tricks , this is the working one for me on kubuntu 14.04.3 lts . thanks! – Jonas Jan 8 '16 at 20:44

This is a common problem if you are connecting remotely, so the solution is to not forward your locale. Edit /etc/ssh/ssh_config and comment out SendEnv LANG LC_* line.

  • 6
    I was trying other answers, but forgot I was connecting remotely until I saw your answer. Different locales on the ssh server and client was causing the problem. – Hieu Feb 27 '15 at 6:32
  • 2
    On OSX (connecting to ubuntu) it's at /etc/ssh_config – Michiel de Mare Jun 3 '15 at 10:01
  • One-liner to do this: sed -e '/SendEnv/ s/^#*/#/' -i /etc/ssh/ssh_config (useful for server provisioning) – Albin Jun 16 '15 at 16:57
  • I couldn't set LC_ALL on the locale machine but it fixed my problem with the remote server, thanks. – Alexander Shlenchack Aug 26 '16 at 20:33
  • 1
    Probably worth noting that you have to edit the file on the local machine not the remote. – Clashsoft Jul 9 at 18:08

There is a command for that:

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

It updates /etc/default/locale with provided values.

  • 4
    This is legit! Don't forget to sign out / reload your shell, or else you won't see the changes. Don't forget to check out the approved answer for generating and reconfiguring locales. – Erik Zivkovic Feb 8 '16 at 10:28
  • 1
    Running locale still doesn't show any utf values. – Cerin Apr 18 '17 at 23:00
  • @Cerin: Myybe, a call to locale-gen is missing. Before, one has to do apt-get install locales. – koppor Aug 16 '17 at 6:19
  • 1
    This won't change LANG for the root shell on Ubuntu 16.04, as it is overruled in /root/.profile. – Willem Dec 31 '17 at 16:44

What worked for me on 12.10 was this:

apt-get install language-pack-en-base  

This was after dpkg-reconfigure locales produced no results.

  • 1
    This is the best answer. It's not that my locales were setup incorrectly, but they didn't actually exist. I think this is similar to the OP's problem as well ("No such file or directory" is pretty clear if your locale is set right!). – Breakthrough Oct 27 '13 at 21:49
  • 1
    I was getting the OPs issue ever time i was using apt-get on Ubuntu 12.04 This solved it perfectly without having to edit any files. – Deepend Jun 10 '14 at 10:13
  • "language-pack-en-base is already the newest version." – karlingen Aug 10 '15 at 7:51
  • Logout and Login may help – S.M.Mousavi Nov 16 '15 at 18:09
  • Worked for me in an ubuntu chroot under debian. Thanks :) – Wyatt8740 Feb 18 '16 at 13:25

Don't forget exit your SSH session (or your X11) by exiting and logging back in again. All of these suggestions didn't work for me unless I logged back in....

  • 1
    This comment should get more upvotes or atleast the fact needs to be highlighted in every answer. – ni8mr Dec 9 '16 at 14:24

For Ubuntu 12.10 none of the above worked except for ratzs' solution. I recommend adding this to your /etc/bash.bashrc file:

export LC_ALL="en_ZA.UTF-8"
export LC_CTYPE="en_ZA.UTF-8"
  • Of all the solutions above. This is the only that worked for me. – JohnnyQ May 11 '16 at 6:56

I was stuck in a weird state where my local machine is set to es and so the remote machine (via vagrant) had been provisioned in an un-handled state. Therefore, I had to use the manual export= only to facilitate a successful dpkg-reconfigure. Then the system is fine.

export LC_ALL="en_US.UTF-8"
sudo dpkg-reconfigure locales
  • Best! Due to dpkg-recofigure displays mojibake. – Orient Jun 28 '17 at 13:47

I wrote a bash script to fix above issue.The above answers are useful but setting the locale variables by simply exporting the values in shell variable will work only for a session. I permanently solved this issue by exporting the locale variables in .bash_profile file. You can also use /etc/profile file instead of .bash_profile.

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

Don't forget to source the .bash_profile and follow the script in easy setup.

You can try:

export LANGUAGE=ru_RU.UTF-8
export LC_CTYPE=ru_RU.UTF-8
export LC_NUMERIC=ru_RU.UTF-8
export LC_TIME=ru_RU.UTF-8
export LC_COLLATE=ru_RU.UTF-8
export LC_MONETARY=ru_RU.UTF-8
export LC_MESSAGES=ru_RU.UTF-8
export LC_PAPER=ru_RU.UTF-8
export LC_NAME=ru_RU.UTF-8
export LC_ADDRESS=ru_RU.UTF-8
export LC_TELEPHONE=ru_RU.UTF-8
export LC_MEASUREMENT=ru_RU.UTF-8
export LC_IDENTIFICATION=ru_RU.UTF-8
export LC_ALL=ru_RU.UTF-8

where ru_RU is your country code.

As said here in the Debian Wiki, you can edit /etc/locale.gen and add all locales (or uncomment them, I had a list of all locales but all except the one I used as comments) you wish to have support for on your system. Then, execute

sudo dpkg-reconfigure locales

to update the locales on your system. Now, all of the locales you added/uncommented in /etc/locale.gen are available on your system without any warnings.

Current accepted answer is not sufficient in the troubleshoot strategy because you can have an human error. You setup your system to en_US but you have en_GB enabled in/etc/locale.gen like I had in the thread here for Raspberry Pi 3b. You should have all your used locales enabled in /etc/locale.gen.

I had en_GB.UTF-8 UTF-8 only enabled in /etc/locale.gen. I should have there only enabled en_US.UTF-8 UTF-8 because of other commands run for it. So I commented GB and uncommented US, and everything work now

masi@raspberrypi:~ $ sudo vim /etc/locale.gen

masi@raspberrypi:~ $ sudo locale-gen 
Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.

masi@raspberrypi:~ $ sudo a2enmod rewrite && a2enmod headers && a2enmod ssl
Module rewrite already enabled
Module headers already enabled
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Module socache_shmcb already enabled
Module ssl already enabled

Now, I do not get those locale mistakes with any commands.

System: Raspbian Jessie
Hardware: Raspberry Pi 3b

If you use KDE environment, check the setlocale.sh file in ~/.kde/env/:

$ cat ~/.kde/env/setlocale.sh 
export LANG=en_US.UTF-8
export LANGUAGE=en_US:ru:en
  • this saved my ass.... thank you! Unbelievable how many places this locale crap is being set in... and how in the world does KDE manage to screw things up by mixing my two different locales (is_IS for location, money, etc and en_EN for language into a non-existent is_EN locale)! Grmpfh. – StFS May 27 '16 at 11:05
  1. You may need to run sudo dpkg-reconfigure also for the application you have installed while "locale" settings have been invalid / not matching.

    While system locale was incorrectly setup I installed vim. Later when system locale was fixed I saw a situation that vim was showing utf-8 characters incorrectly as strange symbols while nano and less were showing them correctly. Running

    sudo dpkg-reconfigure vim
    

    appeared to fix the issue after the system settings were fixed.

  2. I also noticed the same thing as already mentioned: You may need to disconnect/reconnect SSH to make changes visible.

Adding the following text to ~/.profile works for me:

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

I am using Ubuntu 16.04 LTS 64-bit server on Linode.

This worked for me when I had the same problem (based on the solution provided by dman):

sudo sh -c "echo -e 'LC_ALL=en_US.UTF-8\nLANG=en_US.UTF-8' >> /etc/environment"
  • I wasn't quite sure how to add the url to the comment. @EliahKagan – pythonhunter Aug 27 '14 at 6:28
  • 1
    No problem--the date/timestamp next to a comment is what links to it directly. ...So, I've noticed glarrain's comment (calling for > instead of >>) seems like a reply to dman's. I don't actually know which way is right or best, but if you have any insight into this you could expand this answer with more information. (You don't have to though.) – Eliah Kagan Aug 27 '14 at 6:32

I was having a problem running 'Agnoster' theme with oh-my-zsh in my dockerized workstation with similar error messages. (It's faster than wsl IMO and I can mount docker.sock into this container via Hyper-V VM managed by Docker For Windows, which allows me to do docker stuff)

Combining some of the suggestions from answers helped fixed it for me.

I added this to my Dockerfile

RUN apt-get install -y locales
RUN sudo locale-gen "en_US.UTF-8"
RUN echo 'LANG="en_US.UTF-8"' > /etc/profile.d/locale.sh
RUN echo 'LANGUAGE="en_US.UTF-8"' >> /etc/profile.d/locale.sh
RUN echo 'LC_ALL="en_US.UTF-8"' >> /etc/profile.d/locale.sh

enter image description here

Here is a gist if you want to give it a try.

protected by Community Jan 1 '15 at 19:12

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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