I noticed I have several unneeded locales installed, for example,
firefox-locale-. I only need one locale.
How to remove all the rest?
First type the
locale command to print out your current locale configuration. Also, you can use
locale -a to display a list of all available locales.
localepurge to remove any unwanted languages, while choosing the ones you want to keep. Note that this method will not change the locales settings on your system. It will just purge the locales you have not selected. Use at your own risk.
sudo apt-get install localepurge
After that, you could reboot or try to run
To reconfigure this, simply enter the following in terminal:
sudo dpkg-reconfigure localepurge
Another way answered here is to
sudo locale-gen --purge <locales YOU WANT TO KEEP>
Unless you have a need to switch to various locales all the time, you can uninstall the unused locales and free up some amount of the storage space in your system.
Install Localepurge via the terminal:
sudo apt-get install localepurge
Once the installation is done, it will remove all locale files from your system that you have no need for.
Note: Some of the commands below require root privileges, consider the use of
man locale-gen, locales are set in several files.
The main configuration file, which has a simple format: every line that is not empty and does not begin with a # is treated as a locale definition that is to be built.
A directory containing locale.gen snippets provided by language-pack packages. Do not edit these manually, they will be overwritten on package upgrades.
Locales are compiled (generated) into a single file.
Usual default locale archive location.
Comprehensive details on locales at the Arch Wiki.
To list available (known) locales, run any of the following commands (with minor output differences).
To check the (already) generated locales, run the following command.
To check the currently used locale, run any of the following commands (with minor output differences).
Locales are typically set by uncommenting lines in
/etc/locale.gen, after which running
locale-gen is required.
nano /etc/locale.gen # uncomment desired lines (locales)
This will compile (generate) locales into
/usr/lib/locale/locale-archive for each uncommented line in
/etc/locale.gen and under
/var/lib/locales/supported.d/, whether they were previously compiled or not.
Alternatively, the command
will uncomment the corresponding line in
locale-gen while generating the desired locale and only this one.
Note: The implementation of
locale-gen is distro dependent. For instance, the command above is valid in Ubuntu/Debian but not in ArchLinux.
locale-gen, the compiled archive is erased and all locales in
/etc/locale.gen and under
/usr/lib/locale/locale-archive are regenerated anew. The command
locale-gen --purge <locale> doesn't do what the modifier suggests but the opposite: It removes all compiled locales except those indicated. To make sure only specific locales are generated when
locale-gen is issued or and update is performed both
/usr/lib/locale/locale-archive must be considered.
To remove locales in
/etc/locale.gen, simply comment the desired lines and regenerate the locales using
To remove locales under
/var/lib/locales/supported.d/ is trickier. Since any file
/var/lib/locales/supported.d/<code> depends on the package
language-pack-<code>-base, any change on the former will be restored when the latter is updated. To solve this, simply hold the packages that update files under
/var/lib/locales/supported.d/. The command that achieves this in Ubuntu/Debian is the following.
Workaround. A more intrusive but general solution that prevents changes under
/var/lib/locales/supported.d/ is to set files in it with the "immutable (i)" attribute. So instead of removing files, empty them. For instance:
rm <code> && touch <code> # <code> has been emptied
lsattr <code> # regular attributes
chattr +i <code> # adding (+) immutable
lsattr <code> # checking attributes
Setting and generating locales does not set the system locale. Any of the following commands achieves this.
echo LANG=<code> | sudo tee /etc/locale.conf # reboot (might be ignored in Ubuntu)
localectl set-locale LANG=<code>
apt install localepurge, but this only stops new packages from installing locales files. "This option will become active for packages unpacked after localepurge has been (re)configured. Packages installed or upgraded together with localepurge may (or may not) be subject to the previous configuration of localepurge."
rm -rI /usr/share/locale/!(en).
Then possibly reinstall packages if they have locales files in their own directories.
rm /dir !() removes files in your current dir (pwd).
https://askubuntu.com/a/624445/795299 (relevant top answer from above link)
apt install --reinstall locales if you accidentally delete a dir.
Install BleachBit, amongst other things it's able to remove locales from any linux OS.
When you launch BleachBit, it may show you the preferences dialog where you can tick which locales you want to keep.
If it doesn't show you this automatically, then you can open it from the triple dot menu up in the top right of the window.
This is my first answer on this site. BleachBit is able to remove files for unwanted languages in your system and applications.
Install BleachBit from your Ubuntu Software or terminal (sudo apt install bleachbit) and open it as root (sudo bleachbit). Go to Preferences and under Languages check all the languages you want to keep. Now on the left panel, under System, check Localizations. If you want to know how much space these localization files are taking up in your system, click the Preview button. Use the Clean button to actually free up the space. Hope this helps.
In the screenshot, you can see BleachBit deleting localization files from gedit text editor.