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

Written on Friday October 25, 2019 - Permalink - Tags: linux, bash, locale, utf-8

Problem

In some Linux distributions (in my case it is Arch) you can meet with such warning in terminal:

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

Solution

Uncomment line # en_US.UTF-8 UTF-8 (even if you got another locales uncommented) in locale file and regenerate them.

Auto way

To comment line containing specific string with sed, simply do:

sed -i '//s/^/# /g' file

And to uncomment it:

sed -i '//s/^# //g' file

In this case run command:

sudo sed -i '/en_US.UTF-8 UTF-8/s/^# //g' /etc/locale.gen

To check if sed parsed file correctly:

grep "en_US.UTF-8 UTF-8" /etc/locale.gen

Manual way

In Arch distribution run command:

sudo nano /etc/locale.gen

Then find and uncomment following line (usually line 164):

# en_US.UTF-8 UTF-8

Regenerating locales

Uncomment appropriate locales, save file and run:

sudo locale-gen