Locale errors on Ubuntu LinuxΒΆ

When launching an Ubuntu compute instance using the images provided by Canonical, it is recommended to configure the locale using cloud-init. The example below illustrates how the locale can be defined at boot time using the cloud-config syntax.

fqdn: instancename.example.com
locale: en_US.UTF-8

If the locale is not configured appropriately, you may get locale related errors, such as:

  • locale.Error: unsupported locale setting
  • perl: warning: Setting locale failed
  • perl: warning: Please check that your locale settings

These errors can occur while installing packages or performing simple tasks on the operating system.

If you have not defined the locale at boot time, you can still configure it later using the following procedure.

First, ensure that your hostname is defined in /etc/hosts (sudo vi /etc/hosts). If you only have an entry for localhost, add another entry with the name of your compute instance, as shown below: localhost instancename

Use the commands below to configure and generate your locales. Replace en_US.UTF-8 with your desired locale.

export LC_ALL="en_US.UTF-8"
sudo echo "LC_ALL=en_US.UTF-8" >> /etc/environment
sudo dpkg-reconfigure locales