49

I've got a locale problem.
The collating sequence in nautilus and other programs has changed.
I get locale errors appearing in the terminal when I launch a GUI app..

    Gtk-WARNING **: Locale not supported by C library.
        Using the fallback 'C' locale.

The locale command produces error messages

    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_AU
    LANGUAGE=en_AU:en
    LC_CTYPE="en_AU"
    LC_NUMERIC="en_AU"
    LC_TIME="en_AU"
    LC_COLLATE=en_AU.UTF-8
    LC_MONETARY="en_AU"
    LC_MESSAGES=en_AU.UTF-8
    LC_PAPER="en_AU"
    LC_NAME="en_AU"
    LC_ADDRESS="en_AU"
    LC_TELEPHONE="en_AU"
    LC_MEASUREMENT="en_AU"
    LC_IDENTIFICATION="en_AU"
    LC_ALL=

As suggested in askubuntu question, I've run the following commands, but there was no change.

    sudo apt-get install language-pack-en-base
    sudo dpkg-reconfigure locales

I also tried the suggestion in askubuntu question... also no change.

    apt-get install --reinstall locales

I think it began when I temporarily installed and uninstalled the Urdu language Input Method Editor via IBus .. it certainly happened on the same day.

Maybe it is IBus related, but I've not had any problems with it before this.

  • The OS is 10.04
1

13 Answers 13

28

I've managed to get things running "normally" again.

After trying lots of package re-installs etc, including fully removing IBus (all to no effect), I started to think that it may be caused by a config setting which re-installing doesn't modify.

I had noticed that the output from locale was rather bereft, of UTF-8 assignments, so I checked this in a recently installed VM... all entries of LC_* (except LC_ALL, which overrides all the others) were set with the .UTF-8 suffix. so I manually set the LC_* values as shown below.

I probably could have just used LC_ALL="en_AU.UTF-8", but in reading up about this, I've discovered how to customize the system date and time format, and LC_ALL would override my custom setting.

I don't know if I've used the most appropriate method, but it works!

The modified file is: /etc/default/locale

  • This shows the contents before the mod:

    LANG="en_AU.UTF-8"
    LANGUAGE="en_AU:en"
    LC_MESSAGES="en_AU.UTF-8"
    
  • This shows the contents after the mod:

    LANG="en_AU.UTF-8"
    LANGUAGE="en_AU:en"
    LC_CTYPE="en_AU.UTF-8"
    LC_NUMERIC="en_AU.UTF-8"
    LC_TIME="en_AU.UTF-8"
    LC_COLLATE=en_AU.UTF-8
    LC_MONETARY="en_AU.UTF-8"
    LC_MESSAGES=en_AU.UTF-8
    LC_PAPER="en_AU.UTF-8"
    LC_NAME="en_AU.UTF-8"
    LC_ADDRESS="en_AU.UTF-8"
    LC_TELEPHONE="en_AU.UTF-8"
    LC_MEASUREMENT="en_AU.UTF-8"
    LC_IDENTIFICATION="en_AU.UTF-8"
    

The same file in the VM contained only this one line:

    LANG="en_AU.UTF-8" 

1
  • thanks for your post. For the record, I had to restart my system for the fix to work. (perhaps could have used emacs eval-buffer?) May 9, 2011 at 14:47
25

Redefining the locales and reconfiguring might be sufficient to fix the problem:

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

When you run sudo dpkg-reconfigure locales you can select the locale you want by clicking on spacebar and moving with and before hitting Enter.

5
  • 1
    Maybe it's worth to mention that you select languages you want with spacebar.
    – Daniel
    Jul 31, 2014 at 19:02
  • @Daniel I don't understand: spacebar ? Jul 31, 2014 at 19:25
  • 2
    When running dpkg-reconfigure you get list with checkboxes and to select language you have to use spacebar. There's no such information in console program so I thought it would help to write it under the answer. I didn't know how to select these languages.
    – Daniel
    Jul 31, 2014 at 19:44
  • 1
    @Daniel done :) Jul 31, 2014 at 19:55
  • You're a lifesaver @DanielKmak
    – Nimitz14
    Mar 10, 2021 at 22:32
15

I also met this problem ,as you see, your LC_ALL is empty. I did as follows and it helps:

$ sudo vim /etc/environment

and set the LC_ALL to something like en_US.UTF-8,mine is:

LANG="en_US.UTF-8"
LC_MESSAGES="C"
LC_ALL="en_US.UTF-8"

then reboot,and run locale ,and it should be something like:

LANG=zh_CN.utf8
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
2
  • This solution works well on Ubuntu 12.04 LTS precise Jan 29, 2013 at 8:45
  • 1
    Setting LC_ALL is discouraged. "Using LC_ALL is strongly discouraged as it overrides everything. Please use it only when testing and never set it in a startup file." wiki.debian.org/Locale
    – gertvdijk
    Jun 1, 2014 at 21:23
5

If you are remotely connected to the machine over ssh (eg from a macosx device) you need to set these variables on the machine you are connecting from

add the following to ~/.bash_profile

#fix for locale issues when connecting to ubuntu servers
export LANG="en_US.utf8"
export LANGUAGE="en_US.utf8"
export LC_ALL="en_US.utf8"
2
  • 1
    Is this a known fault when connecting from OS X?
    – MindTooth
    Oct 7, 2012 at 9:51
  • no idea if this is by design or a fault/bug
    – Somatik
    Oct 8, 2012 at 10:27
2

I just want to add, that I needed to edit my home profile too:

gedit ~/.profile

So in your case it would look like:

...
LANG="en_AU.UTF-8"
LANGUAGE="en_AU:en"

Log out + Log in. And all is as expected.

1
  • I needed export at the beginning of each line, and I put it in ~/.bashrc.
    – Sparhawk
    Jul 4, 2014 at 15:20
2

I had the same problem for several months, a lot of software tools warned about broken locale settings, and some even refused to run. I want to use English language, but Swedish monetary and number settings.

What finally worked for me was to edit /etc/default/locale where I removed everything in that file. I then started the Unity language setup (Settings -> Language Support), set everything up (Ubuntu wanted to install some missing components) and pressed "Apply System-wide" when I was done.

My /etc/default/locale now looks like this.

LC_NUMERIC="sv_SE.UTF-8"
LC_TIME="sv_SE.UTF-8"
LC_MONETARY="sv_SE.UTF-8"
LC_PAPER="sv_SE.UTF-8"
LC_IDENTIFICATION="sv_SE.UTF-8"
LC_NAME="sv_SE.UTF-8"
LC_ADDRESS="sv_SE.UTF-8"
LC_TELEPHONE="sv_SE.UTF-8"
LC_MEASUREMENT="sv_SE.UTF-8"
LANGUAGE="en"
LANG="en_US.UTF-8"

The big difference between this and my original file is LANGUAGE="en".

1
  • My life saver...
    – John Joe
    Jun 7, 2017 at 9:59
2

It's been a while since this was posted but recently I had problems with "locale" variables and no answer gave me any results. Maybe my own experience could help someone else.

My LANG variable was empty, and this was giving me problems.

$locale

Output:

LANG=
LANGUAGE=en_US
LC_CTYPE=POSIX
LC_NUMERIC=POSIX
LC_TIME=POSIX
LC_COLLATE=POSIX
LC_MONETARY=POSIX
LC_MESSAGES=POSIX
LC_PAPER=POSIX
LC_NAME=POSIX
LC_ADDRESS=POSIX
LC_TELEPHONE=POSIX
LC_MEASUREMENT=POSIX
LC_IDENTIFICATION=POSIX
LC_ALL=POSIX

I tried some of the commands like:

sudo locale-gen
sudo dpkg-reconfigure locales

With no success. I tried editing the /etc/default/locale and find out it was already O.K:

$cat /etc/default/locale

Output:

LANG=en_US.UTF-8
LC_NUMERIC="es_CO.UTF-8"
LC_TIME="es_CO.UTF-8"
LC_MONETARY="es_CO.UTF-8"
LC_PAPER="es_CO.UTF-8"
LC_NAME="es_CO.UTF-8"
LC_ADDRESS="es_CO.UTF-8"
LC_TELEPHONE="es_CO.UTF-8"
LC_MEASUREMENT="es_CO.UTF-8"
LC_IDENTIFICATION="es_CO.UTF-8"

Also my .pam_environment file seemed to be right:

$cat .pam_environment

Output:

LANGUAGE=en_US:en
LANG=en_US.UTF-8
LC_NUMERIC=es_CO.UTF-8
LC_TIME=es_CO.UTF-8
LC_MONETARY=es_CO.UTF-8
LC_PAPER=es_CO.UTF-8
LC_NAME=es_CO.UTF-8
LC_ADDRESS=es_CO.UTF-8
LC_TELEPHONE=es_CO.UTF-8
LC_MEASUREMENT=es_CO.UTF-8
LC_IDENTIFICATION=es_CO.UTF-8
PAPERSIZE=letter

I din't want to add extra stuff to profile or bash files, mainly because although it could solve the problem I wouldn't know the cause, and that annoyed me.

Finally I wondered if something was already overriding "locale" variables and I ran the next command:

$cat .bashrc | grep LANG

Output:

unset LANG

So I found two lines on my .bashrc file that where the cause (I'm not pasting the whole file):

unset LANG
export LC_ALL=POSIX

I don't know how or when those lines ended up on my bash file, but I'm completely sure I didn't write them, maybe my .bashrc was replaced when I was working with some web-development stuff, I really don't know, but since I know this was unintentional and there are people out there with no clue about what's causing "locale" misbehavior, maybe this could help them. Anyway commenting those lines and a reboot solved the problem for me. Here I answered the same question focused on sublimeT3 complaints about the LANG variable.

1

Seems an update fried locales somehow. The fix I found was to log out, change the language selected before logging in, and logging in again.

It might also help to reinstall the locales in synaptic, though I cannot confirm that this is what fixed it for me, I think it was logging out or something.

2
  • Re logging in and changing language. I see no actualy way to change language at logon.. I see text which mentions changing language, but there is no option (buttons or suchlike).. perhaps that is because I only have Australian English enabled.... and I have run all the commands above.. so it is stil a mystery at the moment...
    – Peter.O
    Apr 1, 2011 at 20:54
  • @red.bear: Try installing language-pack-en and language-support-en, then repeat the process above.
    – RolandiXor
    Apr 1, 2011 at 22:41
1

I tried editing locale file and choosing different languages at login.

Filtering for broken packages with Synaptic and completely removing the 9 offending packages worked for me (libreoffice and python uno).

But, I am unable to install LibreOffice without apparently corrupting the package manager. It does, however, install.

I'm on 11.04 i386. Disclaimer: There was a power failure during the last part of my installation as Ubuntu was downloading updates.

1

I had the same problem but going to System > Administration > Language Support may solve your problem because it may ask you to install some packages and then it will be fine!! It worked for me so i guess it'll do the same to you!!

0

Run

export LC_ALL="zh_CN.utf8"
ibus-setup

and select one of of the options for input method as you wish.

0

I had a similar problem (most noticeable in Thunderbird) to the en_AU example here - but i'm from en_NZ - and after some trial-and-error with Ubuntu 17.10 my fix was to update ~/.pam_environment, replacing all other entries (mostly en_AU and en_US) with en_NZ, then rebooting.

A shame that you can't just set your locale and have it do what it claims to do - most disappointed that that running dpkg-configure locales doesn't actually seem to do anything useful.

0

I was trying to deploy Rails application with Capistrano, from macbook m1 pro to Ubuntu 22.04 server.

In ubuntu 22.04 server:

I added the following to ~/.bash_profile

#fix for locale issues when connecting to ubuntu servers
export LANG="en_US.utf8"
export LANGUAGE="en_US.utf8"
export LC_ALL="en_US.utf8"

I run these commands:

$ export LC_ALL="en_US.UTF-8"
$ sudo dpkg-reconfigure locales
  • Click up and down arrow to focus "en_US.UTF-8"
  • Click TAB to focus
  • Click Enter

Restart Ubuntu server

$ sudo shutdown -r now 

Then I run this command

$ locale

Output:

LANG=en_US.utf8
LANGUAGE=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=en_US.utf8

Looks like everything is fine. But the issue is not solved.

In macbook m1 pro:

Then I updated settings on mac terminal

Terminal -> Settings... -> Profiles -> Advanced -> Uncheck “Set locale environment variables on startup” You will then need to quit the Terminal application, and open terminal. This issue should be fixed.

Now I run cap staging deploy command, in macbook m1 pro, works!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .