Fix your locales! A Script for Debian

Fix your locales! A Script for Debian
Photo by Andrew Neel / Unsplash

I used Debian a lot. Occasionally I get oddball locale issues.
This is the code I use to fix said issues. It effectively strips out all the locales except en_US.UTF-8

Technically this is not best practice, as there is a small chance it will cause issues under certain conditions. I have yet to encounter any of those conditions, and it has historically solved 100% of my locale problems, however use at your own risk!

apt-get update
# Install locales package
apt-get install -y locales
mv /etc/locale.gen /etc/locale.gen.bak
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
mv /etc/default/locale /etc/default/locale.bak
echo "LANG=en_US.UTF-8" > /etc/default/locale

# Generate locale
locale-gen

# Export env vars
echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
echo "export LANGUAGE=en_US.UTF-8" >> ~/.bashrc