Fixing “No such file or directory” locale errors

Tags: , , , ,


While working on a new ubuntu karmic system I ran across the following locale error when attempting to perform a dist-upgrade. I was able to reproduce it by running ‘dpkg-reconfigure locales’ thinking that this might fix the error, sadly it did not.

Here’s the error I was seeing:

root@harrowdown:~# dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US"
    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

If you boil the error message down a bit the problem becomes a bit more clear. It’s trying to say that the “en_US” locale could not be found:

perl: warning: Setting locale failed.
        LANG = "en_US"

To install the missing “en_US” locale run ‘locale-gen en_US’ which should yeild the following output.

root@harrowdown:~# locale-gen en_US
Generating locales...
  en_US.ISO-8859-1... done
Generation complete.

And as you can see the errors are no longer printed when I call dpkg-reconfigure (or anything else for that matter).

root@harrowdown:~# dpkg-reconfigure locales
Generating locales...
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  en_CA.UTF-8... done
  en_DK.UTF-8... done
  en_GB.UTF-8... done
  en_HK.UTF-8... done
  en_IE.UTF-8... done
  en_IN.UTF-8... done
  en_NG.UTF-8... done
  en_NZ.UTF-8... done
  en_PH.UTF-8... done
  en_SG.UTF-8... done
  en_US.ISO-8859-1... up-to-date
  en_US.UTF-8... up-to-date
  en_ZA.UTF-8... done
  en_ZW.UTF-8... done
Generation complete.

[ad]

8 Responses to “Fixing “No such file or directory” locale errors”

  1. Kanwar Says:

    Thanks,

    It worked for me

    [Reply]

  2. Mohsin Says:

    It didn’t work for me. On running “locale-gen en_US” I got the messages that your blog post suggest but running “dpkg-reconfigure locales” again gave the same errors:

    root@server:~# dpkg-reconfigure locales
    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = “en_IN”
    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
    Generating locales…
    en_US.ISO-8859-1… up-to-date
    Generation complete.

    [Reply]

  3. sixeightzero Says:

    Mohsin,

    Try running an:

    export LANGUAGE=’en_US’

    Worked for me

    [Reply]

  4. Edller Says:

    Thank you very much!
    You are the man!

    [Reply]

  5. Tobu Says:

    I had a similar problem, except that `dpkg-reconfigure locales` wasn’t enough to solve it. The locale `fr_FR.UTF-8@euro` was in my environment (in the output of the `locale` command), but locales.postinst / locale-gen didn’t know it should be generated.

    The solution is either to generate it:

    sudo localedef -i fr_FR@euro -f UTF-8 fr_FR.UTF-8@euro

    (building fr_FR.UTF-8@euro from the /usr/share/i18n/locales/fr_FR@euro locale and the /usr/share/i18n/charmaps/UTF-8.gz charmap)

    Or to make sure `dpkg-reconfigure locales` will regenerate it, which is done by appending `fr_FR.UTF-8@euro UTF-8` to either /var/lib/locales/supported.d/local (Ubuntu) or /etc/locale.gen (Debian).

    Here is more info on serverfault: http://serverfault.com/questions/231025/fix-stubborn-setting-locale-failed#answer-237252

    [Reply]

  6. Fay Says:

    I had similar pmbelors, to the point where I couldn’t run deluge( torrent client). It terminated with the error : locale::facet::_S_create_c_locale name not valid .I tried your export suggestion, but it was not enough. After a lot of fruitless mucking around, I examined my /etc/default/locale file & noticed that LANG was defined as en_GB.UTF-8:en so I changed that to just the UTF-8 locale. Lo! & Behold deluge is fine & no more errors. I think it may have been caused by a dodgy update script, as its only just happened today.I must also say Roll on, Gnome-Shell 3.2 for Wheezy , because right now in Wheezy we’ve got Gnome 3 sans extensions, which must be the worst of both worlds

    [Reply]

  7. Nikit Saraf Says:

    Thank you so much!!
    Worked perfectly for me!

    [Reply]

  8. Demetris Says:

    Worked for me on ubuntu server 12.04.2 64bit:
    sudo locale-gen el_CY.UTF-8

    Generating locales…
    el_CY.UTF-8… done
    Generation complete.
    udo dpkg-reconfigure locales
    Generating locales…
    el_CY.UTF-8… up-to-date
    en_AG.UTF-8… done
    etc
    etc
    Thanks buddy 😀

    [Reply]

Join the Conversation