How to set LC_NUMERIC to English permanently?

20,591

Solution 1

Append the value to your ~/.bashrc file:

echo 'export LC_NUMERIC="en_US.UTF-8"' >>~/.bashrc

To make it applicable from the current session of bash, source the ~/.bashrc file:

source ~/.bashrc

Example: Here i am changing from en_US.UTF-8 to C:

$ locale | grep LC_NUMERIC
LC_NUMERIC="en_US.UTF-8"

$ echo 'export LC_NUMERIC="C"' >>~/.bashrc

$ source ~/.bashrc 

$ locale | grep LC_NUMERIC
LC_NUMERIC=C

This will change the locale for only the user running the command, for system wide change you need to add the value to /etc/default/locale, check the added portion below.


You can also add the value to the systmwide locale file, /etc/default/locale, which will be read at start. To put it there:

echo 'LC_NUMERIC="en_US.UTF-8"' | sudo tee -a /etc/default/locale

Or

sudo bash -c 'echo "LC_NUMERIC=\"en_US.UTF-8\"" >>/etc/default/locale'

Solution 2

The "official" technique to change locale settings for number formatting system-wide is:

sudo update-locale LC_NUMERIC=en_US.UTF-8

After that, restart your system.

If it still does not work, then probably your graphical desktop environment overwrites the system-wide locale settings. On a personal computer, it is best to configure it so that it does not modify the system-wide locale settings at all. How to do this depends on the desktop environment you use. I made instructions for LXQt for this.

Source: A comment by Ron above. I wanted to turn it into a proper answer as it's the official and most straight-forward technique.

Solution 3

Graphical logins do not read shell startup files ( ~/.bashrc, ~/.profile and so on ) by default and also should not because these are bash specific.

So it is better to use /etc/environment for system wide environment settings and ~/.xsessionrc for user specific settings.

PAM should by default read /etc/environment - check that

/etc/pam.d/login /etc/pam.d/sshd /etc/pam.d/su /etc/pam.d/cron

includes the line

session       required   pam_env.so readenv=1

-> https://wiki.debian.org/EnvironmentVariables

Share:
20,591

Related videos on Youtube

Maria
Author by

Maria

Updated on September 18, 2022

Comments

  • Maria
    Maria almost 2 years

    I need to change LC_NUMERIC to English (I have Ubuntu in Spanish) because of the dots and the commas, but if I use LC_NUMERIC="en_US.UTF-8" when I exit the terminal and I open it again, LC_NUMERICis again in Spanish.

    Does anyone know how to solve this?

    • Ron
      Ron over 8 years
      Have you tried update-locale LC_NUMERIC=en_US.UTF-8?
  • Maria
    Maria over 8 years
    Thank you!! It works perfectly, I installed Ubuntu one week ago and I am trying to figure out everything, really useful answer!
  • heemayl
    heemayl over 8 years
    @Maria Glad i could help and of course welcome to the Ubuntu world !!
  • heemayl
    heemayl almost 8 years
    @Stephen The redirection (and echo) is running in a subshell (spawned by bash -c), not in the current shell, check the single quotes around.
  • Stephen
    Stephen almost 8 years
    Ah, thanks. I didn't see the single quotes. You're absolutely right.
  • Arnaud
    Arnaud over 4 years
    Did not work when I only changed /etc/default/locale and logged out then in. Worked when changed ~/.bashrc and /etc/default/locale and restarted computer. Don't have time to test all possible combinations. Tested with the calculator on a Ubuntu 18.04 system which was shipped with French locale, needed the decimal separator to be a dot because I often copy results from the calculator to other programs or web apps, which only understand the decimal point.
  • Tak
    Tak about 4 years
    @heemayl Is there a way to change LC_NUMERIC while running a script only without having to change the basic or locale files so that's it's kind of only for the current script I am running?
  • woodz
    woodz almost 4 years
    Graphical logins do not read shell startup files ( ~/.bashrc, ~/.profile and so on ), and what about the login shell?