Fix bash warning setlocale LC_CTYPE cannot change locale UTF-8

18 Dec 2025 - 3 min read
Fix bash warning setlocale LC_CTYPE cannot change locale UTF-8

If you’ve encountered the error message -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory when working on a Linux system, you’re not alone. This common issue occurs when your system’s locale settings are misconfigured or incomplete. In this guide, I’ll show you how to resolve this error quickly and permanently.

Table of Contents

Understanding the Error

The setlocale: LC_CTYPE: cannot change locale (UTF-8) warning appears when:

  • Your system is trying to use a locale that isn’t properly installed or configured
  • The locale environment variables are set incorrectly
  • The locale files are missing or corrupted

This error typically appears when you open a new terminal session or SSH into a remote server.

The Solution

To fix this error permanently, you need to update your system’s locale configuration. Follow these two simple commands:

Step 1: Update the Locale Configuration

Terminal
sudo update-locale LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8

This command updates the locale configuration file (usually located at /etc/default/locale) to set both LC_CTYPE and LANG to en_US.UTF-8.

Step 2: Load the New Configuration

Terminal
source /etc/default/locale

This command loads the updated locale settings into your current shell session, applying the changes immediately without requiring a logout or reboot.

Verification

To verify that the fix worked, you can check your current locale settings:

Terminal
locale

You should see output similar to:

LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=

Alternative: Generate Missing Locale

If the above solution doesn’t work, you may need to generate the locale first:

Terminal
sudo locale-gen en_US.UTF-8
sudo update-locale LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
source /etc/default/locale

The locale-gen command generates the specified locale if it’s not already available on your system.

Common Locale Options

While this guide uses en_US.UTF-8, you can replace it with your preferred locale:

LocaleDescription
en_US.UTF-8US English
en_GB.UTF-8British English
de_DE.UTF-8German
fr_FR.UTF-8French
es_ES.UTF-8Spanish
ja_JP.UTF-8Japanese
zh_CN.UTF-8Chinese (Simplified)

To see all available locales on your system:

Terminal
locale -a

Conclusion

The -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8) error is easily resolved by updating your system’s locale configuration. The two-command solution provided in this guide will permanently fix the issue and ensure your terminal sessions work smoothly without locale warnings.

ThinhHV

About ThinhHV

DevOps • Fullstack Developer • Amateur Photographer