Fix Perl Setting Locale Failed Error in Debian/Ubuntu

When installing software on Debian or Ubuntu systems, you might encounter Perl locale warnings indicating that your system’s language settings are not properly configured. These errors don’t prevent installation but can be annoying when repeatedly displayed during package installations or updates. The root cause is typically missing locale configurations or improperly set LANG or LC_* variables.


QUICK FIX
Generate and configure the missing locales by running:

# locale-gen en_US.UTF-8 en_GB.UTF-8 && update-locale

. Log out and log in again.


Understanding the Error

ERROR MESSAGE

$ apt-get install [package-name]
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = "en_US:en",
	LC_ALL = (unset),
	LC_CTYPE = (unset),
	LC_NUMERIC = (unset),
	LC_COLLATE = (unset),
	LC_TIME = "en_GB.UTF-8",
	LC_MESSAGES = (unset),
	LC_MONETARY = (unset),
	LC_ADDRESS = (unset),
	LC_IDENTIFICATION = (unset),
	LC_MEASUREMENT = (unset),
	LC_PAPER = (unset),
	LC_TELEPHONE = (unset),
	LC_NAME = (unset),
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
perl: warning: Setting locale failed.


This error occurs when Perl (which many Debian/Ubuntu package scripts use) can’t find the locale configurations needed for proper language handling. The issue typically arises when your system has environment variables pointing to locales that aren’t generated or when locale packages aren’t fully installed. The warning shows a mix of en_US.UTF-8 and en_GB.UTF-8 settings.

Solution Explained

Terminal showing the solution
Terminal showing the solution

The solution involves generating the missing locales and updating the system locale settings. The locale-gen command creates the necessary locale files in the system, while update-locale refreshes the system configuration. This approach properly configures both the en_US.UTF-8 locale (used for most system settings) and en_GB.UTF-8 locale (specified in LC_TIME). After running these commands, Perl will be able to find the required locale data files and properly format dates, times, currency, and other region-specific information.

Examples

  1. Fixing a specific locale issue: When you need only the en_US.UTF-8 locale
    # locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8

    This approach focuses solely on generating and setting the en_US.UTF-8 locale, which is sufficient if you don’t need British date formats or other regional settings.

  2. Setting consistent locales: Setting LC_ALL to eliminate mixed locale settings
    # locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8

    Using LC_ALL overrides all individual LC_* variables, ensuring consistent behavior across all localization categories. This is useful when you’re experiencing conflicts between different locale settings.

Additional Notes

  • You must have root privileges to generate locales – use sudo if you’re not logged in as root.
  • Some cloud or minimal installations may not have the locales package installed – run apt-get install locales first if locale-gen isn’t found.
  • For a complete solution in automated environments, consider adding export LC_ALL=C.UTF-8 to your /etc/environment file to prevent these warnings in scripts and automated processes.


Comments and Discussions
Linux Forum