Change or Set System Locales in Ubuntu VPS

How to Change or Set System Locales in Ubuntu VPS?

To change or set system locales in Ubuntu VPS, proceed as follows:

  • Check current locale settings
  • List available locales
  • Generate the desired locale
  • Set and update the system locale
  • Reboot the System (Optional).

After buying a Linux VPS running Ubuntu, setting locales in Ubuntu VPS offers a localized user experience tailored to regional and linguistic settings. Setting locales in Ubuntu VPS allows customized language, country, date and time formats, and monetary conventions.

This article provides a comprehensive guide to configuring locales (language settings) for Ubuntu VPS from the command line.

Steps to change or set locales in Ubuntu

Here’s a step-by-step guide on how to change or set locales in Ubuntu VPS:

1. Checking the current system locales in Ubuntu VPS

Open the terminal on your Ubuntu VPS and run the following command to display the current locale settings for your system:

locale

Sample output:

LANG=en_US.UTF-8
LANGUAGE=en_US
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=

As you see, we can define major parameters, but the first one is the most important (LANG=en_US.UTF-8) which defines the default system language.

Note: Using the “-k” option with the locale command, allows you to view detailed information about a specific environmental variable. For example to display more information about LC_MESSAGES (defines the language of the user interface or the window manager), run the following command:

locale -k LC_MESSAGES

2. List available locales

To see a list of available locals which are installed in our Ubuntu system, use the following command:

locale -a

Sample output:

C
C.UTF-8
en_US
en_US.utf8
...
POSIX

3. Generate the desired locale (if no locale is set)

If the desired locale is not available in the list, you can set it:

sudo locale-gen [locale]_UTF-8  # Replace [locale] with your desired locale code

For example, to generate the “de_DE.UTF-8” locale for German in Ubuntu VPS, use:

sudo locale-gen de_DE.UTF-8

Output:

Generating locales…
de_DE.UTF-8 … done
Generation complete.

Note: The /usr/share/i18n/SUPPORTED file contains a list of available locales including their language, country, and encoding combinations.

4. Set system Locale in Ubuntu VPS

The  /etc/default/locale file contains default locale settings in the Ubuntu system that exist on the condition that the locale has already been set for the system. To change or set the system locale you can edit this file manually using your favorite text editor (if exists) or set the system locale using update-locale tool.

  • Using the update-locale command

After generating the locale, the /etc/default/locale file also is generated. Therefore, you can set/ change the locale by updating the system locale using:

sudo update-locale LANG=[locale]_UTF-8  # Replace [locale] with your desired locale code
  • Manually Editing Configuration Files

Alternatively, you can adjust the locale manually, to do this you must edit the /etc/default/locale file using your favorite text editor like nano:

sudo nano /etc/default/locale

Add or modify the following lines to set your desired locale:

LANG=[locale]_UTF-8
LC_ALL=[locale]_UTF-8  # Optional, sets all locales to the same value

Replace [locale] with your desired locale code.

5. Apply the Changes

After editing the /etc/default/locale file to set your desired locale, you need to export the locale settings to apply changes using the following command:

source /etc/default/locale

This command loads the new locale settings into the current shell session.

Alternatively, you can log out and log back into your user session to apply the changes.

6. Reboot the Ubuntu system

Reboot your system to ensure locale changes take effect system-wide:

sudo reboot

7. Verify the changes

Verify the current locale settings are set correctly by running the following command:

locale

you must see the new locale values you set in /etc/default/locale.

How to reconfigure the locale settings in Ubuntu VPS?

To regenerate the supported locale list through the interface guide for selecting and configuring locales, you can use the following command:

sudo dpkg-reconfigure locales

This command simplifies the process of managing locale settings.

How to check the system locale in Linux?

To display your current locale in the Ubuntu system use the following command:

locale

This command displays information about the current locale or all system locates.

Is it safe to change system locale?

Yes, changing the Ubuntu system locale is generally safe and you do not need to worry about that. However, it is recommended to choose a locale that is compatible with your applications to avoid potential issues with character encoding and formatting.

What are Ubuntu locales?

Ubuntu locale is a set of environment variables that defines the language, regional settings, and character encoding used by the system and affect how text, numbers, dates, and other locale- data are displayed.

Conclusion

Changing or setting system locale in Ubuntu VPS, allows you to change the default language to a new one. This guide is useful when you have one Ubuntu system and you are looking for a solution to customize language, country, date, and time formats or set different languages for different functions such as error and system messages on your Ubuntu VPS.

This guide has helped you to change or set the system locale in Ubuntu VPS.

To get more information about locale and update-locale commands, refer to their man page by running commands ” $ man locale ” and ” $ man update-locale “.

If you face the issue in changing or setting the locale in Ubuntu, it is worth checking the ~/.profile, ~/.bashrc, and ~/.bash_profile configuration files to customize and control the user’s shell environment and behavior.

Leave a Reply

Your email address will not be published. Required fields are marked.