5

This self-answered question solves the following issues:

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

and some other locale related problems.

EDIT: Restricting this to my own answer only seems, in retrospect, rather inefficient. Please feel free to add your 2cents. Or as many as you can spare....

4 Answers 4

10

We are working completely in the shell (bash).

The first thing everyone should do is

sudo dpkg-reconfigure locales

The output may be the errors mentioned above and a list of locales that the script generates. Note that the locales generated there are the only ones valid for your system. As you can see the language settings are just a bunch of environment variables. You can, just for fun, try a different language bash like this:

LANG=es_NI.UTF-8 bash
ls somedirectorynamethatdoesnotexistonyoursystem

Tu hablas espaniol? :-) (if the es_NI.UTF-8 was not in your list of locales just choose another)

Ok. Obviously the LANG environment variable helps with the rest of the settings, because, in our spanish bash we can now do

dpkg-reconfigure locales

or whatever command whose error messages led you here, and there should be no errors. If there are, then there's something more sinister wrong that will not be covered by this post.

So, where do we set this variable LANG? A quick search through the /etc/ directory (with rgrep LANG /etc/*) leads us to the file /etc/default/locale. There you can set the value of the variable to something different/correct. For example

LANG=en_US.UTF-8

(That one should always work) To finish this: The variables mentioned in the error messages, all "derive" from LANG, meaning that they default to whatever LANG is set to, but you can set them to your liking if you want your shell to speak a different language. The package language-env helps with this.

sudo apt-get install language-env
set-language-env

The script is meant to automatically create entries for your .bashrc etc.

I haven't tried it myself.

I hope this helps someone.

Btw:

  1. you can find the generated locales under ls usr/share/locale
1

I have tried many many solutions and none of them worked for me on Debian 7.

So, I added export LC_ALL=en_US.UTF-8 to /etc/default/locale and the warnings have gone.

2
  • You should edit /etc/default/locale instead.
    – n.st
    Sep 21, 2013 at 20:04
  • That's the only thing that worked for me, setting LC_ALL in /etc/default/locale Mar 26, 2020 at 21:30
0

Short answer:

Run dpkg-reconfigure locales as root.

(While in the dialog press Enter until you find your language, see its number, press Enter again, until you are asked for the number. Enter the number of you language, Enter, done. If you don't know better, take the UTF8-Version of you language)

Resources: https://wiki.debian.org/Locale

0

I was using German VPS and couldn't change locale because there was no English language pack installed.

After installing I could finally change locale

aptitude install language-pack-en

You must log in to answer this question.

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