Table of Contents#
- Prerequisites
- Checking Available Languages and Locales
- Installing Language Packs
- Generating Locales
- Configuring the System Locale
- Updating Environment Variables
- Verifying the Language Change
- Setting the Language for the Login Screen (GDM)
- Troubleshooting Common Issues
- Conclusion
- References
Prerequisites#
Before starting, ensure you have:
- Ubuntu 22.04 LTS: This guide is tailored for Jammy Jellyfish.
- Sudo Privileges: You’ll need administrative access to install packages and modify system files.
- Terminal Access: Open a terminal via
Ctrl+Alt+T(GUI) or SSH (remote/server). - Internet Connection: To download language packs (if not already installed).
Checking Available Languages and Locales#
Ubuntu uses "locales" to define language, region, and character encoding (e.g., en_US.UTF-8 for U.S. English with UTF-8). First, check which locales are already installed and available.
2.1 Listing Installed Locales#
To see all currently installed locales, run:
locale -aOutput example (truncated):
C
C.utf8
en_US.utf8
POSIX
If your target language (e.g., fr_FR.UTF-8 for French) isn’t listed, you’ll need to install its language pack and generate the locale.
2.2 Finding Language Pack Names#
Ubuntu language packs follow a naming convention: language-pack-<language-code>, where <language-code> is a 2-letter ISO 639-1 code (e.g., fr for French, es for Spanish, de for German).
To search for available language packs, use:
apt search "language-pack-<code>"Example (search for Spanish packs):
apt search "language-pack-es"Look for packages like language-pack-es (full pack) or language-pack-es-base (minimal base pack).
Installing Language Packs#
Language packs contain translations and locale data. Install the pack for your target language using apt.
Example: Install Spanish (Spain)#
For Spanish (Spain), the language code is es, and the locale is es_ES.UTF-8. Install the pack with:
sudo apt update && sudo apt install language-pack-es- Why
language-pack-es? This meta-package installs all necessary files for Spanish, including translations for system tools and desktop environments. - For minimal installs: Use
language-pack-es-base(contains only core locale data, no translations).
Generating Locales#
After installing the language pack, generate the specific locale (e.g., es_ES.UTF-8) to make it available system-wide.
Step 1: Edit the Locale Configuration File#
Open /etc/locale.gen with a text editor (e.g., nano):
sudo nano /etc/locale.genStep 2: Uncomment Your Target Locale#
Find the line for your locale (e.g., es_ES.UTF-8 UTF-8) and remove the # to uncomment it:
# es_ES.UTF-8 UTF-8 # Before
es_ES.UTF-8 UTF-8 # AfterSave and exit (Ctrl+O, Enter, Ctrl+X in nano).
Step 3: Generate the Locale#
Run locale-gen to apply changes:
sudo locale-genOutput:
Generating locales (this might take a while)...
es_ES.UTF-8... done
Generation complete.
Configuring the System Locale#
Now set the new locale as the system default. Use one of two methods: update-locale (traditional) or localectl (systemd-based).
5.1 Using update-locale#
update-locale edits /etc/default/locale, the file that defines system-wide locale variables.
Set the primary locale (LANG) and fallback languages (LANGUAGE):
sudo update-locale LANG=es_ES.UTF-8 LANGUAGE=es_ES:esLANG: Primary locale (e.g.,es_ES.UTF-8).LANGUAGE: Colon-separated list of fallback languages (e.g.,es_ES:es= Spanish (Spain) first, then generic Spanish).
5.2 Using localectl (Systemd Method)#
localectl is a systemd tool for managing system locale and keyboard settings. It updates /etc/locale.conf (used by systemd) and is preferred for modern Ubuntu systems.
Set the locale with:
sudo localectl set-locale LANG=es_ES.UTF-8To verify localectl settings:
localectl statusOutput:
System Locale: LANG=es_ES.UTF-8
VC Keymap: n/a
X11 Layout: us
X11 Model: pc105
X11 Options: lv3:ralt_switch
Updating Environment Variables#
Locale changes won’t apply to your current terminal session until you refresh environment variables.
For GUI Users#
Log out and log back in. This restarts your desktop session and applies the new locale.
For CLI/Server Users#
Source the system locale file to apply changes immediately:
source /etc/default/locale # If using update-locale
# OR
source /etc/locale.conf # If using localectlFor persistent changes in all shells, restart your shell or reboot the system:
sudo rebootVerifying the Language Change#
Confirm the locale is set correctly with these commands:
1. Check All Locale Variables#
localeExpected output (for Spanish):
LANG=es_ES.UTF-8
LANGUAGE=es_ES:es
LC_CTYPE="es_ES.UTF-8"
LC_NUMERIC=es_ES.UTF-8
LC_TIME=es_ES.UTF-8
...
2. Check Primary Locale#
echo $LANGOutput:
es_ES.UTF-8
Setting the Language for the Login Screen (GDM)#
The GNOME Display Manager (GDM) login screen may not automatically inherit the system locale. To set its language:
Method 1: Use localectl (Recommended)#
localectl often configures GDM automatically. If not, run:
sudo localectl set-locale LANG=es_ES.UTF-8Reboot, and the login screen should reflect the new language.
Method 2: Edit GDM Configuration#
If localectl fails, edit GDM’s custom config file:
sudo nano /etc/gdm3/custom.confAdd/modify the LANG line under [daemon]:
[daemon]
LANG=es_ES.UTF-8Restart GDM (note: this logs out all GUI users!):
sudo systemctl restart gdm3Troubleshooting Common Issues#
9.1 Locale Not Generating#
Issue: locale -a still doesn’t list your locale after running locale-gen.
Fix:
- Ensure
/etc/locale.genhas the locale uncommented (Step 4.2). - Regenerate locales with verbose output to debug:
sudo locale-gen --verbose es_ES.UTF-8
9.2 Language Not Applying After Reboot#
Issue: locale shows the correct variables, but system tools/menus still use the old language.
Fix:
- Check if your desktop environment (e.g., GNOME, KDE) has per-user language settings. Override them to "System Default" in the GUI settings.
- Verify
/etc/default/locale(or/etc/locale.conf) has no typos (e.g.,es_ES.UTF-8vs.es_ES.utf8—case matters!).
9.3 Missing Language Packs#
Issue: Errors like "locale not found" during locale-gen.
Fix:
- Reinstall the language pack:
sudo apt reinstall language-pack-<code> - Search for alternative packs with
apt search "language-pack-<code>"(e.g.,language-pack-es-base).
Conclusion#
Changing the system language on Ubuntu 22.04 via the command line is a powerful skill for managing remote servers, headless systems, or automating setups. By following these steps—installing language packs, generating locales, configuring system variables, and verifying changes—you can seamlessly switch between languages. Remember to log out/in or reboot for changes to take full effect, and use locale or localectl to troubleshoot if issues arise.
References#
- Ubuntu Locale Documentation
- man
locale - man
update-locale - man
localectl - Debian Locale Guide (applicable to Ubuntu)