How to Remove Unwanted Locales in Ubuntu: A Step-by-Step Guide


10 views

When working with Ubuntu systems, you might occasionally add locales accidentally or temporarily. For example, running:

sudo locale-gen zh_TW

This generates the Chinese (Taiwan) locale files. However, these locales remain in your system even when no longer needed, as shown by:

locale -a
# Output shows:
zh_TW

Ubuntu stores locale definitions in two main locations:

/usr/share/i18n/locales/
/var/lib/locales/supported.d/

The generated locale binaries are typically found in:

/usr/lib/locale/

To fully remove a locale (using zh_TW as our example):

# 1. First, remove from supported locales
sudo rm /usr/lib/locale/zh_TW

# 2. Clean up locale-archive (if exists)
sudo localedef --delete-from-archive zh_TW

# 3. Regenerate locales
sudo dpkg-reconfigure locales

# 4. Verify removal
locale -a | grep zh_TW
# Should return no output

For Ubuntu systems, you can use the locale-purge package:

sudo apt-get install locale-purge
sudo locale-purge

This will remove all locale data except those marked as supported in /etc/locale.gen.

To avoid accidentally adding unnecessary locales:

  1. Always check locale -a before generating new locales
  2. Consider using specific packages instead of full locales when possible
  3. Regularly clean up unused locales with locale-purge

If you encounter errors during removal:

# Check for locked locale files
sudo lsof /usr/lib/locale/zh_TW

# Force regeneration if needed
sudo locale-gen --purge

When working with Ubuntu systems, you might accidentally generate unnecessary locales using commands like sudo locale-gen zh_TW. These locales appear in your system's locale list (locale -a), potentially cluttering your environment or causing conflicts in multilingual applications.

First, verify which locales are currently available on your system:

locale -a

This will output something like:

C
C.UTF-8
en_US.utf8
zh_TW

Ubuntu stores locale definitions in two main locations:

/usr/lib/locale/
/var/lib/locales/supported.d/

The generated locale files are typically in /usr/lib/locale/, while configuration is in /var/lib/locales/supported.d/.

To completely remove a locale (e.g., zh_TW), follow these steps:

1. Delete the locale definition

sudo locale-gen --purge zh_TW

2. Remove from supported locales

sudo sed -i '/zh_TW/d' /var/lib/locales/supported.d/*

3. Clean up locale files

sudo rm -rf /usr/lib/locale/zh_TW*

After completing these steps, verify the locale is gone:

locale -a | grep zh_TW

No output means the locale was successfully removed.

For a more automated approach, install localepurge:

sudo apt-get install localepurge
sudo dpkg-reconfigure localepurge

This tool automatically removes unused locale files when packages are installed or removed.

  • Don't remove essential locales like C or en_US
  • Some applications might cache locale settings - restart them after changes
  • Backup important files before deletion

Consider keeping locales if:

  • You're developing multilingual applications
  • Your system serves international users
  • You frequently switch between languages