Fixing LC_CTYPE: cannot change locale (UTF-8)

February 28, 2013 at 20:35

Today I experienced a weird behavior when I was trying to compile reStructuredText with sphinx. While I was able to run locally ‘make html’ without issues, it was failing when I executed the same command in a remote shell from my Macbook with OS X 10.8.2.

The root of all evil was that OS X terminal was not setting properly the LC_CTYPE variable. Every time I was logging in the Linux machine from my local machine I had this message:

warning: setlocale: LC_CTYPE: cannot change locale (UTF-8)

Linux remote machine was expecting something like ‘es_ES.UTF8’ while my remote terminal was setting it to ‘UTF8’.

What I’ve done is simply add this line to my .bash_profile:

And voilĂ , problem fixed 🙂 I used ‘es_ES’ because my keyboard is in Spanish from Spain, but you can use ‘en_US’ for example.