167

I try to setup postgress in OS X Lion, and find that is not correctly setup the LOCALE environment var.

This is what is set:

LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

I expect something with UTF-8. This is a clean OS X Lion setup, with spanish language. I don't move anything.

I don't know how setup it to UTF-8.

In the terminal settings, is check UTF-8 and set LOCALE in open, despite that don't work.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
mamcx
  • 15,916
  • 26
  • 101
  • 189
  • 2
    That's odd. It should work in Terminal by default, assuming you're using the default shell (bash) and the default terminal settings profile (Basic). Note that if you alter the encoding or change "set locale environment variables" they only take effect in new terminals, not ones that are already open. – Chris Page Aug 25 '11 at 23:16
  • I use zsh (using oh my zsh! installer), maybe is that? – mamcx Aug 26 '11 at 22:06
  • Possibly. Try running zsh without any custom configuration to see if the problem goes away. Use **Shell > New Command** to run `zsh --no-rcs` and `zsh --no-rcs --no-global-rcs` to narrow down the problem. Also, try just running the `locale` command without a shell via **New Command** and see what it reports. – Chris Page Aug 28 '11 at 02:04
  • @ChrisPage I had the exact same output as the OP, with those settings enables in the Terminal. I had to switch `set locale environment variables` off, restart the terminal and then switch it back on to get the right environment to show up. – Chris Apr 09 '16 at 00:14
  • There is a thorough answer to this question on [Ask Different](https://apple.stackexchange.com/questions/21096/where-does-lang-variable-gets-set-in-mac-os-x/302348#302348). – starfry Oct 16 '17 at 10:12

6 Answers6

340

I noticed the exact same issue when logging onto servers running Red Hat from an OSX Lion machine.

Try adding or editing the ~/.profile file for it to correctly export your locale settings upon initiating a new session.

export LC_ALL=en_US.UTF-8  
export LANG=en_US.UTF-8

These two lines added to the file should suffice to set the locale [replace en_US for your desired locale, and check beforehand that it is indeed installed on your system (locale -a)].

After that, you can start a new session and check using locale:

$ locale

The following should be the output:

LANG="en_US.UTF-8"  
LC_COLLATE="en_US.UTF-8"  
LC_CTYPE="en_US.UTF-8"  
LC_MESSAGES="en_US.UTF-8"  
LC_MONETARY="en_US.UTF-8"  
LC_NUMERIC="en_US.UTF-8"  
LC_TIME="en_US.UTF-8"  
LC_ALL="en_US.UTF-8"  
saurabh
  • 6,687
  • 7
  • 42
  • 63
wormintrude
  • 3,516
  • 1
  • 16
  • 6
  • 2
    Also, I originally noticed the issue while using iTerm2. This workaround seems to work for both iTerm2 and Terminal. – wormintrude Nov 17 '11 at 03:51
  • 1
    Spent an hour looking a solution for this matter thanks a lot for posting this man. I can confirm it works on both Terminal and iTerm2. – Mariano Cavallo Aug 21 '12 at 08:02
  • Thank you :) I hope this is easiest and the most stable fix for this locale issue. Been bothered by this for some time now, but could not easily grasp why all my nix boxes would suffer from a malfunction locale issue. – MindTooth Oct 07 '12 at 17:43
  • thanks so much! after tons of searches, most of them direct me to the server i ssh to. this changes on Mac OSX really fix the problems. – sunnycmf Mar 13 '14 at 08:36
  • Is there a way to export global system language instead of hardcoded? I have `ru_RU` locale and *maybe* my project can clone some Latvian or Ukrainian user with other locale. I think that there is some variable in OS X that returns `"ru_RU.UTF-8"` or similar for other locales. – Даниил Пронин May 22 '14 at 23:32
  • 11
    I have a `.bash_profile` on my home folder and `.profile` was not being sourced when `.bash_profile` was present. I needed to manually source `.profile` inside `.bash_profile` – Bruno Medeiros Jun 08 '15 at 02:43
  • [Here](http://www.cyberciti.biz/faq/os-x-terminal-bash-warning-setlocale-lc_ctype-cannot-change-locale/) you can see how to choose this option for Mac's *Terminal* application. – Atcold Oct 08 '16 at 20:36
  • 7
    Amazing, that did it, just a note, once you use zsh, don't be dumb as me... the config there is `~/.zshrc`... well now works like a charm – Redrick Feb 13 '17 at 16:05
  • This also files display of Unicode filenames in Midnight Commander – Tim Babych Feb 19 '17 at 00:27
  • 2
    There is no reason to set both `LANG` and `LC_ALL`. Only `LANG` should be set. First, they both do the same - set default values for all locale variables (e.g. `LC_TIME`, `LANGUAGE`) - with `LC_ALL` having precedence over `LANG`. `LANG` is the one meant to be used in standard configuration, while `LC_ALL` is only for debugging purposes (as it overwrites everything else). [Some reference](https://wiki.archlinux.org/index.php/Locale#Variables) – Robert Kusznier Sep 19 '19 at 00:14
  • 1
    @RobertKusznier Yes, only `LANG` should be set. However `LANG` and `LC_ALL` do not have the same effect . The value of [`LANG`](https://keith.github.io/xcode-man-pages/locale.1.html#LANG) will be used only for _unset_ LC_* variables. The value of [`LC_ALL`](https://keith.github.io/xcode-man-pages/locale.1.html#LC_ALL) on the other hand will _override_ any other LC_* variables. The value of `LC_ALL` will be used wether the other variables are set or not. – Stefan Schmidt Oct 24 '22 at 09:53
  • @StefanSchmidt True. – Robert Kusznier Oct 25 '22 at 12:23
23

I recently had the same issue on OS X Sierra with bash shell, and thanks to answers above I only had to edit the file

~/.bash_profile 

and append those lines

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
FredericK
  • 1,612
  • 1
  • 18
  • 26
  • 1
    It really help. I don't have `bash_profile` and I have create it manually. And without put `export` to `bash_profile`, every time we reset terminal the language will rollback. – Linh Nov 13 '18 at 01:55
9

if you have zsh installed you can also update ~/.zprofile with

if [[ -z "$LC_ALL" ]]; then
  export LC_ALL='en_US.UTF-8'
fi

and check the output using the locale cmd as show above

❯ locale                                                                                                                                           
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
tostao
  • 2,803
  • 4
  • 38
  • 61
Milland
  • 99
  • 1
  • 1
  • For me, this was not an alternative solution but the only solution that worked. Also, I needed to restart my system afterwards to propagate the changes to my IDE. Thanks m8 :) – Corram Nov 02 '22 at 11:01
7

This is a headbreaker for a long time. I see now it's OSX.. i change it system-wide and it works perfect

When i add this the LANG in Centos6 and Fedora is also my preferred LANG. You can also "uncheck" export or set locale in terminal settings (OSX) /etc/profile

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Marcel Kraan
  • 71
  • 1
  • 1
2

I had this issue with MacOS High Sierria.

Screenshot 1

You can set up locale as well as language to UTF-8 format using below command :

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Screenshot 2

Now in order to check whether locale environment is updated use below command :

Locale

Screenshot 3

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
2
if [[ -z "$LC_ALL" ]]; then
  export LC_ALL='en_US.UTF-8'
fi

then check for locale, output should be :

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424