Skip to content

Instantly share code, notes, and snippets.

@opsxcq
Created April 7, 2016 20:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opsxcq/6f80d13554676b3bd701006d8e6c9fcd to your computer and use it in GitHub Desktop.
Save opsxcq/6f80d13554676b3bd701006d8e6c9fcd to your computer and use it in GitHub Desktop.
Fix locale error on Debian Wheezy/Jessie (perl: warning: Setting locale failed)
If you got this error running apt-get or some other program:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
Just run this code:
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales
Copy link

ghost commented Oct 3, 2018

I have found this to work well too, for a non-interactive alternative. Please test first on your Debian build.

$ sed -i '/^#.* en_US.* /s/^#//' /etc/locale.gen && locale-gen

Copy link

ghost commented Oct 3, 2018

For the record, that last one doesn't survive a reboot, but this one does.

echo "locales locales/default_environment_locale select en_US.UTF-8" | debconf-set-selections
echo "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8" | debconf-set-selections
rm -rf "/etc/locale.gen"
dpkg-reconfigure --frontend noninteractive locales &> /dev/null
echo "Locale for the target host was set to en_US.UTF-8 UTF-8."

I put that in a sh script and it runs nicely as root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment