595

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 ?

JJD
  • 862
HackToHell
  • 6,726

20 Answers20

589

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!

Sheharyar
  • 1,238
  • 269
    did not work for me – Umair Ayub Apr 24 '14 at 07:43
  • 4
    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
  • this didn't work for me in ubuntu 14.04, I'm still getting console errors. – alexserver Sep 21 '15 at 18:31
  • so finally I had to add export LC_ALL="en_US.UTF-8" manually in my .bachrc file. and this fixed the error prompts. But... why is that this variable wasn't configured by gen-locale ? isn't this supposed to be managed by this command ? – alexserver Sep 21 '15 at 18:37
  • 5
    Logout and Login may help – S.M.Mousavi Nov 16 '15 at 18:09
  • @S.M.Mousavi Tried rebooting as well, only manually exporting the variables seems to fix the issue – Prashanth Chandra Jan 12 '16 at 01:56
  • 1
    Remember open a new terminal to test it – deFreitas Jun 21 '16 at 01:57
  • 6
    @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 http://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
  • Thanks. I was not able to update my softwares for so long and sometimes the operating system used to crash because of stopping the process and restarting the system – Paul Thomas Apr 17 '17 at 06:36
  • In fact it only worked when executing "sudo dpkg-reconfigure locales" -> select "en_US.UTF-8" from the long list (use space to select) -> Enter -> select again en_US.UTF-8 as default -> Enter. – Anonymous Apr 19 '17 at 07:24
  • my two cents,

    you might need to install locales first, especially if you got an error from just trying locale -a

    On Ubuntu, simply install locales by this command sudo apt-get install locales

    – Bhoom Suktitipat Dec 18 '17 at 07:55
  • Worked perfectly in Windows Subsystem for Linux under Ubuntu 16.04.3 LTS. Not sure how locales got broken but this fixed it. – WinEunuuchs2Unix Dec 27 '18 at 23:36
  • Works great!. It really helps – Thanh Hải May 13 '19 at 10:39
  • I had to type 159 and than 3 after running sudo locale-gen "en_US.UTF-8" – alper Mar 02 '22 at 09:20
  • This worked for me even though /etc/default/locale and the output of locale don't get changed. – Sridhar Sarnobat Aug 30 '22 at 04:58
  • locale-gen does not take any arguments, it just generates all locales that have previously been selected via dpkg-reconfigure locales, so it's useless here. – ggll Dec 02 '22 at 11:02
420

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.

Nicolás
  • 279
Marcin
  • 4,209
  • 131
    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
  • 30
    Updated /etc/default/locale and no more warnings. Thanks – ohho Feb 26 '13 at 07:00
  • 9
    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 06:01
  • 16
    @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 09 '14 at 21:22
  • 2
    I am facing the same issue in my Ubuntu Cloud Image – Umair Ayub Apr 24 '14 at 16:03
  • I used this method but I quoted the locale value, like LC_ALL="en_US.UTF-8" then I still got the error. Removing that quote fix the problem. – HVNSweeting Aug 13 '14 at 10:23
  • 1
    You need to log-out and log back in for these changes to have any effect. – Basil Mar 12 '15 at 13:18
  • 1
    (Old question, I know, but) LC_ALL should NOT be touched, it's an override (for all (the other) locale settings), local and remote. It means that you're, basically, forcing it (which I don't think is a viable solution :)) – Nostromov May 30 '15 at 20:25
  • 15
    DON'T FORGET TO LOGPUT AND RE-LOGIN! – S.M.Mousavi Nov 16 '15 at 18:05
  • This is what worked for me on a fresh Raspbian install. /etc/default/locale only had the LANG line without an LC_ALL line. – John Baber-Lucero Dec 22 '15 at 03:48
  • 1
    @Nostromov If I leave out the LC_ALL line, I'll continue getting errors. This is the only viable and reliable solution that works for me. Anything I should watch out for as a result of setting LC_ALL? – Prashanth Chandra Jan 12 '16 at 01:58
  • 2
    it is need exit of session and relogin – jruzafa Apr 06 '16 at 11:00
  • Just want to say that this works. – Ru Chern Chong Feb 01 '18 at 03:46
  • @glarrain To apply a partial fix on this base is dangerous: Just making it to overwrite deletes other parts of /etc/environment. It will work, without complaining - but may break something to be noticed much later. – Volker Siegel Apr 21 '19 at 06:30
  • @prasanthchandra : Where are the errors appearing? Which file have you put this in (see glarain's answer)? And fundamentally : What is output of (1) locale and (2) locale -a? – Rusi Jan 07 '20 at 12:12
  • 1
    Basically @nostromov is correct. LC_ALL should not be set. If things get to "working" by setting it it's a kludge – something somewhere else is broken. And remains so – Rusi Jan 07 '20 at 12:15
174

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.

Rinzwind
  • 299,756
  • 10
    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
  • I believe the sudo is missing. Perhaps it should be: sudo dpkg-reconfigure locales. This worked for me after a fresh install of Ubunty 14.10 Desktop 64-bit. – bgoodr Feb 14 '15 at 19:02
  • Logout and Login after above solution may help. – S.M.Mousavi Nov 16 '15 at 18:06
  • somehow sudo locale-gen en_US is required on top en_US.UTF8. hopefully it will solve the issue for good (after multiple Ubuntu versions) – prusswan Mar 19 '16 at 18:09
  • It just is the perfect solution. – Arush Salil Aug 17 '16 at 07:19
  • Fow AWS EC2 , this will work. – Yogesh Yadav Sep 29 '16 at 23:13
  • 2
    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
  • Thank you! This, but not the other answers, solved my problem with Ubuntu 19.10 on AWS EC2. – amitp Nov 11 '19 at 18:20
145

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

export LC_ALL="en_US.UTF-8"
devav2
  • 36,312
ratz
  • 1,459
  • 1
  • 9
  • 2
  • 3
    This sweet fix worked for me on my Amazon-EC2 image (Was running their default RHEL AMI) Thanks so much! :) – gideon Dec 01 '12 at 15:07
  • This one worked for me with my digitalocean's Ubuntu 12.04 image. – Inan Sep 25 '13 at 11:49
  • 3
    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
  • 1
    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! – Yunus Jan 08 '16 at 20:44
  • @sobi3ch And thereafter you likely don't need LC_ALL. (You should find LANG properly set after the reconfigure) ie as temporary hack setting it is fine. Stable long-term not. (Yeah thus is old. Sayin' because it's currently reinforcing a bad practice) – Rusi Jan 11 '20 at 16:19
  • I was using zsh (oh-my-zsh) but this was what finally pointed me in the right direction. ~/.zshrc contains the lines: ```# You may need to manually set your language environment

    export LANG=en_US.UTF-8

    ``` Uncommenting the export LANG line fixed it for me with xfce4-terminal on Ubuntu 18.04 (in a stripped-down VM with XFCE desktop.)

    – hotwebmatter Jan 26 '20 at 01:21
  • old comment but just saved me on Ubuntu 20.04 lts :) – taiyodayo Oct 20 '21 at 14:50
109

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.

warvariuc
  • 2,305
user249697
  • 1,199
  • 1
  • 7
  • 5
95

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.

To apply the changes, you can

source /etc/default/locale
Katu
  • 3,593
  • 26
  • 42
sgtpep
  • 1,067
  • 5
    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 Živković Feb 08 '16 at 10:28
  • 2
    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 06:19
  • 2
    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
  • 1
    *** update-locale: Error: invalid locale settings: LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 – alper Mar 02 '22 at 08:51
  • 1
    @alper You first need to locale-gen "en_US.UTF-8" and then and only then check it on sudo dpkg-reconfigure locales – Pablo Bianchi Jun 23 '23 at 00:09
  • This update-locale is what solved the problem after about 2 hours tring to install a package that compain, so "Really: thanks" – Abd-Elaziz Sharaf Mar 16 '24 at 01:53
37

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.

Seth
  • 58,122
  • 2
    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 07: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 :) – Wyatt Ward Feb 18 '16 at 13:25
  • I'd extend the solution: you can generate a command to install all the languages currently mentioned in your locale (whatever mix it may be). Here it is: locale|tr -d '"'|cut -d= -f2|cut -d_ -f1|sort|uniq|while read lang; do [[ $lang ]] && echo apt install language-pack-$lang-base; done (I won't state that it's the shortest possible, but it works). – gluk47 Jul 08 '16 at 10:51
  • This also works on Ubuntu 18.04 LTS. – PHZ.fi-Pharazon Oct 18 '22 at 19:02
  • This doesn't work on Debian, while apt-get install locales-all worked fine – The Godfather Nov 06 '23 at 16:31
22

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....

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

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
13

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"
11

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.

Ajeet Khan
  • 523
  • 7
  • 11
9

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.

Eric Carvalho
  • 54,385
Koss
  • 199
  • 2
  • 2
8

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

7

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.

GabLeRoux
  • 131
  • 5
msrd0
  • 247
5

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
MaximKostrikin
  • 184
  • 1
  • 4
  • 1
    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
  • I have been struggling with this for weeks! No other answer helped me. I couldn't even assume that KDE messes with the locale in its own way. I didn't know about the setlocale.sh file and not a single tutorial mentions it. – user2513149 May 28 '21 at 06:00
4

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 06: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 06:32
3
  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.

msrd0
  • 247
ajaaskel
  • 103
3

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.

1

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, RHEL, Redhat, CentOS I used

sudo dnf install langpacks-de

for the german (de) language packs. Logged out and 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
erik
  • 657
  • dnf are not Ubuntu or flavor commands, how is this helpful on this site? https://askubuntu.com/help/on-topic – guiverc Sep 29 '20 at 07:59
  • This problem is not specifically an Ubuntu problem. I gave general instructions in the first paragraph. And then an example of how to do it on a specific distribution, where I had the problem. It is basic knowledge how to translate that to another distributions package management system. – erik Sep 30 '20 at 08:34
  • If you wanted to post this answer, I feel the question should have been re-asked on SE Unix & Linux and the answer used there, thus being on-topic. – guiverc Sep 30 '20 at 08:38
  • My answer is absolutely on topic. None of the answers tells what the real problem is, the source of the problem. Package installation is trivial, or should be asked in a different question. It is quite similar on all distributions, also on Debian or Ubuntu. And the rest of the solution works fine on every modern linux distribution. And I mentioned explicitly my distributions. Instead of complaining you could add the Debian/Ubuntu commands. That would be helpful. – erik Sep 30 '20 at 16:16
0

remove locales using localepurge you don't need and reboot

apt install localepurge