Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

up vote 2 down vote accepted

See locale-gen:

 locale-gen --purge en_US.UTF-8


 echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale
share|improve this answer
Thanks, but I'm getting File "/usr/share/apt-listchanges/", line 32, in <module> sys.stderr.write(_("Can't set locale; make sure $LC_* and $LANG are correct!\n"))... –  kenn Feb 23 '12 at 8:02
Try LANG=en_US.UTF-8 locale-gen --purge en_US.UTF-8 –  Stone Feb 23 '12 at 9:36
This morning, with a clean state of VM, it worked! Thanks! –  kenn Feb 23 '12 at 19:30
Hmm… when you run locale-gen --purge en_GB.UTF-8 on a clean installation, you get this unexpected output: Generating locales (this might take a while)... en_US.UTF-8... done Generation complete. Any ideas how to set the list of locales as you do in dpkg-reconfigure locales non-interactively? –  TwoWholeWorms Aug 1 '14 at 16:14

Could not get the answer above to work. Instead, I use this method (for Dockerfiles):

# Configure timezone and locale
echo "Europe/Oslo" > /etc/timezone && \
    dpkg-reconfigure -f noninteractive tzdata && \
    sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    sed -i -e 's/# nb_NO.UTF-8 UTF-8/nb_NO.UTF-8 UTF-8/' /etc/locale.gen && \
    echo 'LANG="nb_NO.UTF-8"'>/etc/default/locale && \
    dpkg-reconfigure --frontend=noninteractive locales && \
    update-locale LANG=nb_NO.UTF-8
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.