How to Fix your Locale on Raspberry Pi

Jared Wolff · 2014.2.24 · 2 Minute Read · raspberry pi · raspbian

Main image

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. It’s used 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!

Last Modified: 2020.3.7

Subscribe here!

You may also like

Deploy HomeBridge On Raspberry Pi Using Resin.io

I’ve been nerding out. It’s something I just can’t stop sometimes. Most recently working on making our home more connected and efficient. Part of the effort was experimenting with…

Raspberry Pi Getting Interactive With Websockets

In order to get interactive with your now serial enabled Raspberry Pi we need a framework that will provide the ability to communicate in real time over the web. For example, first…

Cross Compiling on Mac OSX for Raspberry Pi

In my previous posts, I came to the realization that the Raspberry Pi is not very fast! This results lots of chair spinning time while waiting for my projects to compile. A After I…