Running package updates, connecting via SSH, or compiling software on Ubuntu only to see repetitive terminal warnings like “perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = ‘en_US.UTF-8’ are supported and installed on your system. perl: warning: Falling back to a fallback locale (‘C.UTF-8’)” clutters terminal logs and can disrupt character encoding. This error occurs when your local environment variables specify a language or region that has not been generated inside the Ubuntu locale archive. Follow this guide to generate missing locales and configure permanent defaults.
Inspect Current System Locale Configuration
Inspecting active locale variables reveals which regional parameter is missing from the compiled operating system archive.
- Open your terminal and run:
locale - Inspect the output list. Notice variables displaying empty quotes or referencing regional dialects (such as
en_US.UTF-8,en_GB.UTF-8, orUTF-8). - Next, check which locales are currently generated and compiled on your system:
locale -a - If the language specified in your
LANGvariable is absent from thelocale -alist, applications like Perl, Python, and APT throw fallback warnings on every execution.
Generate Missing Locales via locale-gen
The locale-gen utility compiles character definitions and language formats into the binary locale database.
- Execute the generation command for your target locale (for example, US English and British English):
sudo locale-gen en_US.UTF-8 en_GB.UTF-8 - Wait for the confirmation output:
Generating locales (this might take a while)... en_US.UTF-8... done en_GB.UTF-8... done Generation complete. - Update the system-wide default configuration:
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
Reconfigure the Locales Package Interactively
If automated commands do not persist across reboots, reconfiguring the base locales package directly writes verified parameters to /etc/default/locale.
- Run the debconf configuration utility:
sudo dpkg-reconfigure locales - In the text-based interface that opens, use the arrow keys to scroll down to
en_US.UTF-8 UTF-8(or your preferred regional dialect). - Press the Spacebar to select the item (an asterisk
[*]will appear). - Press Tab to highlight
<Ok>and press Enter. - On the second screen, select your default system locale from the list and press Enter to apply changes system-wide.
Fix SSH Client Locale Forwarding Stalls
When connecting from macOS or external Linux workstations over SSH, the SSH client frequently forwards local client variables (such as LC_CTYPE=UTF-8) that the remote server does not recognize.
- On the remote Ubuntu server, open the SSH daemon configuration:
sudo nano /etc/ssh/sshd_config - Locate the line reading:
AcceptEnv LANG LC_* - Comment out the line by adding a hash symbol at the beginning:
#AcceptEnv LANG LC_* - Save the file with
Ctrl + O, press Enter, and exit withCtrl + X. - Restart the SSH service:
sudo systemctl restart ssh - Log out and reconnect via SSH. The shell will adhere strictly to server-defined locales without encountering client forwarding mismatch warnings.