Whenever you connect to an Ubuntu server via SSH or run package management commands like sudo apt update or sudo apt install, you may notice multiple lines of bright warning text filling your terminal: “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.”
While this warning does not usually crash your programs immediately, it clutters script outputs and can cause command-line tools to mishandle special characters, accented letters, and UTF-8 text encodings. This error occurs when your environment variables point to a locale definition that has not been compiled or generated inside Ubuntu’s locale repository. This guide explains how to generate the missing locales and configure permanent defaults.
Method 1: Generate Missing Locales Using locale-gen
The fastest and most direct solution is instructing Ubuntu to compile the UTF-8 locale definition that Perl and system libraries are searching for.
- Open your Ubuntu terminal (or active SSH terminal session).
- Compile the standard US English UTF-8 locale by running:
sudo locale-gen en_US.UTF-8 - If you use British English or another regional locale, generate it as well:
sudo locale-gen en_GB.UTF-8 - Reconfigure the system-wide locale packages:
sudo dpkg-reconfigure locales - A terminal menu will appear. Use the arrow keys to scroll down, press the Spacebar to select
en_US.UTF-8(or your preferred language), press Tab to highlight OK, and press Enter. - Select your default system locale on the subsequent screen and press Enter.
Method 2: Set Permanent Environment Variables in /etc/environment
If you connect via SSH from a macOS terminal, macOS automatically forwards your local Mac locale variables (such as LC_CTYPE=UTF-8) across the SSH connection. If Ubuntu lacks that exact identifier, the Perl warning appears. Setting explicit system-wide defaults resolves this cleanly.
- Open the system-wide environment configuration file in the nano editor:
sudo nano /etc/environment - Add the following three lines to the bottom of the file:
LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 - Press Ctrl + O followed by Enter to save the file, then press Ctrl + X to exit nano.
- Apply the new environment settings to your active session:
source /etc/environment
Method 3: Stop SSH from Forwarding Unrecognised Client Locales
If the error only appears when connecting via SSH from a Mac or foreign client, you can configure the OpenSSH daemon on Ubuntu to ignore client locale environment variables.
- Open the SSH daemon configuration file:
sudo nano /etc/ssh/sshd_config - Locate the line that reads:
AcceptEnv LANG LC_* - Comment out the line by adding a hash (
#) symbol at the beginning:#AcceptEnv LANG LC_* - Save and exit nano (Ctrl + O, Enter, Ctrl + X).
- Restart the OpenSSH server service:
sudo systemctl restart ssh - Disconnect and reconnect your SSH session. The client locale forward will be ignored, and Ubuntu will rely on its stable local configuration.
Method 4: Update Locales via update-locale Utility
Ubuntu provides a dedicated management utility named update-locale that writes configuration directly to /etc/default/locale.
- Execute the update-locale utility with full variable definitions:
sudo update-locale LANG=en_US.UTF-8 LC_MESSAGES=POSIX - Verify your currently active locale configuration:
locale - Confirm that all variables (
LANG,LC_CTYPE,LC_ALL) display valid encodings without (unset) warnings.
Ubuntu Locale Diagnostics Reference Table
The table below provides a quick reference for common locale commands and troubleshooting steps:
| Requirement / Step | Terminal Command | Purpose |
|---|---|---|
| Check active locales | locale |
Displays current environment variables and unset flags |
| List installed locales | locale -a |
Shows compiled locales currently available on disk |
| Generate specific locale | sudo locale-gen en_US.UTF-8 |
Compiles missing language and UTF-8 charset files |
| Interactive configuration | sudo dpkg-reconfigure locales |
Visual wizard to pick default language and charsets |
Maintaining Clean Terminal Environments in Ubuntu
Properly configuring UTF-8 locales ensures that command-line text editors, programming compilers (Python, Node.js, Perl), and database clients render Unicode characters and emojis accurately without encoding corruption. Adding standard locale exports into your base server templates prevents this warning from appearing across future cloud server deployments.