If you aren’t using the default locale on your Debian based system, you’ll often run into errors when running things on the command line such as apt-get or Perl. Fixing this is luckily rather trivial.

First of all to verify you have a locale issue, look for warnings or even errors looking like this:

perl: warning: Setting locale failed or perl: warning: Falling back to the standard locale (ā€œCā€)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = "en_US"
are supported and installed on your system.
.
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

To fix this issue, following questions need to be answered:

  1. Is locales installed?
  2. Which locales are necessary?
  3. Which locales are available?
  4. How to generate the necessary locales?

Is “locales” installed?

Run the following command:

sudo apt install locales

Either it will tell you locales is installed already, or it’ll install locales for you. Both are pretty good outcomes.

Which locales are necessary?

To see which locales are required on your system, run the following command:

sudo locale

You’ll want to look for any locales that are not en_US as this is usually default. For example if it mentions de_DE.UTF-8, take note of this. 

Which locales are available?

Run the following command:

sudo locale -a | grep de_DE

Change the “de_DE” to whichever locale your system requires (see previous step). If you’re having a problem with this locale, chances are the output will be empty. To fix this, go to the next step.

How to generate the necessary locales?

This is dependent on your user, if you do not have root permissions (which is unlikely, as the previous steps required sudo) you’ll want to use locale-gen, if you do have root access use dpkg-reconfigure locales. 

In case of dpkg-reconfigure, run:

sudo dpkg-reconfigure locales

Use the arrow keys to navigate this menu and spacebar to select the required locales. Don’t forget to set en_US.UTF-8 as your default on the next menu!

In case of locale-gen run:

locale-gen de_DE.UTF-8

At the end of this, simply log out and back in again, there should be no errors left on your console.