14

I just did a fresh install of ubuntu using debootstrap. When I do sudo aptitude upgrade, I get this error message:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = "en_US:en",
    LC_ALL = (unset),
    LANG = "en_US.ISO-8859-1"
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

Can someone please tell me how to resolve this issue? I see a lot of postings similar to this online but none of them seems to resolve the problem.

I am using Ubuntu 14.04 LTS. Thanks.


FYI:

$ locale -a
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.iso88591
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX

and

$ locale
LANG=en_US.ISO-8859-1
LANGUAGE=en_US:en
LC_CTYPE="en_US.ISO-8859-1"
LC_NUMERIC="en_US.ISO-8859-1"
LC_TIME="en_US.ISO-8859-1"
LC_COLLATE="en_US.ISO-8859-1"
LC_MONETARY="en_US.ISO-8859-1"
LC_MESSAGES="en_US.ISO-8859-1"
LC_PAPER="en_US.ISO-8859-1"
LC_NAME="en_US.ISO-8859-1"
LC_ADDRESS="en_US.ISO-8859-1"
LC_TELEPHONE="en_US.ISO-8859-1"
LC_MEASUREMENT="en_US.ISO-8859-1"
LC_IDENTIFICATION="en_US.ISO-8859-1"
LC_ALL=
Gunnar Hjalmarsson
  • 33,540
  • 3
  • 64
  • 94
user1527227
  • 425
  • 3
  • 6
  • 15
  • 1
    This was answered here already http://askubuntu.com/questions/162391/how-do-i-fix-my-locale-issue Summary: define LC_ALL on /etc/default/locale – h7r Aug 31 '14 at 08:45

6 Answers6

11

An Ubuntu desktop should be set up with UTF-8 encoding. For some reason your system tries to set the latin1 locale en_US.ISO-8859-1. You should really change that.

Maybe the setting takes place in /etc/default/locale.

Whereever it happens, change it to

LANG=en_US.UTF-8

or else you will encounter various locale related surprises.

Gunnar Hjalmarsson
  • 33,540
  • 3
  • 64
  • 94
  • Are you sure that's the one to use? How do you know? – user1527227 May 09 '14 at 15:39
  • @user1527227: Well, almost. ;) Because AFAIK en_US.UTF-8 comes pre-generated on every Ubuntu desktop. But you can easily check it by running the locale -a command. It would be good if you edited the question and added the output of that command. – Gunnar Hjalmarsson May 09 '14 at 16:39
  • i added the info you requested. – user1527227 May 09 '14 at 16:52
  • 1
    @user1527227: Ok, and there we can see en_US.utf8 in the locale -a output. My advice to change from en_US.ISO-8859-1 to en_US.UTF-8 stands. – Gunnar Hjalmarsson May 09 '14 at 17:07
  • Thank you. Do you know how to exactly do that? I do not see /etc/default/locale. Can I just run sudo locale-gen en_US.utf8? – user1527227 May 09 '14 at 17:10
  • @user1527227: No, no, the locale is already generated. Now the configuration should be changed to make use of it. Probably the best way is to go to System Settings -> Language Support, change the selected language item, change it back to English (United States), and then click the "Apply System-Wide" button. – Gunnar Hjalmarsson May 09 '14 at 17:23
  • I'm using ubuntu 14.04 LTE amd64. I don't see Language Support in System Settings. – user1527227 May 09 '14 at 17:41
  • @user1527227: That's strange. (I suppose you mean LTS.) Sounds like your system is not complete. You can make sure it gets completed by running sudo apt-get install ubuntu-desktop – Gunnar Hjalmarsson May 09 '14 at 17:51
  • Oh I have ubuntu but i'm using KDE :). Do you know how to change it from there? – user1527227 May 12 '14 at 17:07
  • @user1527227: Well, no. This is a page where the most common config files for setting environment variables are mentioned: https://help.ubuntu.com/community/EnvironmentVariables – Gunnar Hjalmarsson May 12 '14 at 18:23
  • I just found the command update-locale LANG=en_US.UTF-8. Probably this is the way which works also on future releases since keyboard/locale config is changing all the time in new Ubuntu releases. The command also checks if the values are valid... – Daniel Alder Aug 07 '14 at 09:19
  • @DanielAlder: Right, that's a command line tool to edit /etc/default/locale, which I should have thought of. Thanks! – Gunnar Hjalmarsson Aug 07 '14 at 16:14
10

A permanent solution for locale issue is to export the locale variables in your ~/.bash_profile. You can also use /etc/profile file instead of .bash_profile to have the change take effect for all users on the system.

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 start a new shell or to manually source ~/.bash_profile.

NotTheDr01ds
  • 17,888
Ajeet Khan
  • 523
  • 7
  • 11
  • Just a heads-up -- I wouldn't normally approve an edit that removed a link to your blog, but you did not disclose that you were linking to your personal content in your post. You can add the link back in if you'd like, but please make sure to review Expected Behavior, specifically, "if you mention your product, website, etc. in your question or answer, you must disclose your affiliation in your post." Thanks! – NotTheDr01ds Apr 14 '22 at 04:05
  • Also note that, while I didn't test it, I'm fairly confident that your blog post has an error. You can't source from within an executed script (e.g. ./set_locale.sh as your blog states). The new values will not take effect in the current shell if you do. You would need to source the script itself (e.g. source set_locale.sh) – NotTheDr01ds Apr 14 '22 at 04:12
7

The debootstrap doesn't create a locale. So we use something else as a locale. Use this command:

sudo locale-gen en_US.ISO-8859-1

I hope this helps!

4

This works for me.

  1. export LANGUAGE=en_US.UTF-8
  2. export LANG=en_US.UTF-8
  3. export LC_ALL=en_US.UTF-8
  4. sudo locale-gen en_US.UTF-8
  5. sudo dpkg-reconfigure locales
zx485
  • 2,426
1

What worked for me is as follows:

export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 sudo locale-gen en_US.UTF-8 sudo dpkg-reconfigure locales

For a permanent solution you can put

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

in your .zshrc or .bashrc

Ref

  1. https://jee-appy.blogspot.com/2016/02/set-locale-on-ubuntu-permanent-solution.html
  2. https://www.thomas-krenn.com/en/wiki/Perl_warning_Setting_locale_failed_in_Debian
alpha_989
  • 125
1

Add LC_ALL="en_US.UTF-8" to /etc/environment and then restart the instance/machine

For more info visit this blog

http://www.pixelninja.me/how-to-fix-invalid-locale-setting-in-ubuntu-14-04-in-the-cloud/