As a continuation of posting tips and tricks about the Raspberry Pi I thought I would throw in some mini-posts that some people may find useful or interesting.

So without further ado lets jump into today’s mini-post.

Locale? What the h#$* is a Locale?

After a fresh install of Raspbian I noticed I was getting an error message:

bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

Simply put, a Locale is the way to tell your computer how to interpret what type of characters you are using (i.e. the 26 letters in the English alphabet are some of these characters). So, if you visit a website in another language it is most likely that it is using a different Locale! UTF-8 is meant to be backwards compatible with ascii which many programmers (including myself) are all too familiar with.

But, why is it important?

Good question, the reason is simply because UTF-8 is the defacto standard to decode characters used on about half of every page you visit on the internet. So it’s a good idea to have the correct Locale enabled on your computer and servers (especially your web servers) to avoid errors.

Fixing your Locale.

So, for the people who had the same problem as me, here is the way you fix this issue:

  1. Edit /etc/locale.gen and uncomment the line with en_US.UTF-8

Alternatively, you can run this single command without editing anything manually (Thanks to Andre for this.)

perl -pi -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen

  1. Run locale-gen en_US.UTF-8
  2. Run update-locale en_US.UTF-8

And there you have it. You won’t get any error messages about your locale anymore!

(Note: if you prefer a different encoding scheme you can follow the same instructions to uncomment and enable your preferred one.)

Many thanks to 0x89b.org for the info.

More Raspberry Pi posts

Want more Raspberry Pi Posts? Click here for more!

Think something is missing? Email me.