Ubuntu – How to Set a Locale Non-Interactively on Debian/Ubuntu

debianlocalizationshell-scriptingUbuntu

Usually, I run aptitude -y install locales then dpkg-reconfigure locales to set up locale.

Now I want to put it into a shell script, how can I reliably do the following, automatically / non-interactively?

  • Choose en_US.UTF-8 and set it as system default
  • Disable all other locales
  • (Optional) Verify if /etc/default/locale contains one-and-only entry of LANG=en_US.UTF-8 as expected

Best Answer

See locale-gen:

 locale-gen --purge en_US.UTF-8

and

 echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale