≡ Menu

OS X Terminal: -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory Fix

I am a new Apple OS X Mabbook user. I am getting an error which read as follows when I connect to any remote Linux/Unix/BSD server or machine through OS X ssh Terminal app:

ssh user@server1.cyberciti.biz
Last login: Wed Mar 26 08:45:36 2014 from 1.2.3.4
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

How do I fix this error?

This warning or error is part of both OpenSSH server and OS X ssh terminal client issue. It can be fixed using various methods.

Understanding LC_* environment variables

Type the following command on remote server to display of all locales supported by Glibc:

$ locale -a

Next, type the following command to display settings on your local system (OSX/Unix/Linux based desktop):

printenv
echo "$LC_CTYPE"

Sample outputs:

UTF-8

The above commands display the country and language names, the character encoding used by the locale. Your local ssh client is sending your LC_* environment variables to remote sshd server. In other words, SSH will try to set every LC_* variable you have set on your local OSX system on the remove server too. Here is an example of such problem:

Fig 01: warning setlocale lc_ctype cannot change locale (utf-8)

Fig 01: warning setlocale lc_ctype cannot change locale (utf-8)

Fixing the LC_CTYPE: cannot change locale (UTF-8) error on Linux/OS X

This can be fixed as follows.

Method #1: If you are using the Terminal app on OS X

If you are using the ‘Terminal’ app then click on

Terminal > Preferences > Select Terminal type such as Basic (default) > Advanced tab

Make sure that the ‘Set locale environment variables on startup’ is unchecked as follows:

Fig.02: Fixing OS X terminal by unsetting 'Set locale environment variables on startup' check box

Fig.02: Fixing OS X terminal by unsetting ‘Set locale environment variables on startup’ check box


Here is another screenshot from MacOS X v10.11.6:
Fig.03: Unsetting 'Set locale environment variables on startup' check box on OS X EI Caption

Fig.03: Unsetting ‘Set locale environment variables on startup’ check box on OS X EI Caption


You must close all ssh session and relaunch Terminal app.

Method #2: Preventing OpenSSH Client from sending the LC_* variables on OS X / Linux / Unix desktop

Edit /etc/ssh/ssh_config or /etc/ssh_config file, enter:

$ sudo vi ~/.ssh/config

Remove or comment out as follows:

#SendEnv LANG LC_*

Save and close the file.

Method #3: Install required locale on the remote server

Finally, you can fix this problem either installing the desired locale using the localedef command, or consider choosing a different locale in locale/remote system:

# localedef -i en_US -f UTF-8 en_US.UTF-8
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 25 comments… add one }
  • Mark May 3, 2014, 7:20 pm

    Thank you very much, Nix! This solves my problem! :)

  • Atif May 24, 2014, 7:56 am

    thanks.

    The /etc/ssh_cofig change worked for me too.

    • Gustavo July 11, 2014, 5:13 pm

      Thanks!

    • Leonardo September 7, 2014, 6:58 pm

      Thank you! This was the unique method that worked for me. (I’m using os x mavericks)

  • Devashish August 13, 2014, 7:20 am

    The /etc/ssh_cofig fix worked for me. Thanks!
    It was quick, nice, and easy change.

    In your post, You should change
    sudo vi ~/.ssh/config
    to
    sudo vi /etc/ssh_cofig
    .

    Regards,
    Devashish.

    • Leo March 3, 2017, 8:56 am

      This is path for ubuntu and macOS:

      sudo vi /etc/ssh/ssh_config

  • ohad September 1, 2014, 10:00 am

    Thanks that worked like a charm(Method #1)

  • Ramon November 18, 2014, 5:40 pm

    Thanks a lot!! (solved with method #1)

  • Andrey January 8, 2015, 11:16 am

    Thanks a lot!

  • Zague58 April 12, 2015, 1:07 am

    Funcionó con localedef -i en_US -f UTF-8 en_US.UTF-8, ya no se presenta el problema.

  • MacHamster May 3, 2015, 9:25 am

    Just wanted to say thanks.
    Using iTerm2 – but there’s no option to unset locale variable on startup in the GUI, so the /etc/ssh_config edit was the way to go – and worked.

    • Keijro August 6, 2015, 6:14 am

      In iTerm2 it is done under Preferences -> Profiles -> Terminal
      Uncheck the box “Set locale variables automatically”

  • Mosh May 27, 2015, 1:40 am

    It works!
    Thank you.

  • kde35 July 26, 2015, 7:54 am

    Hi, when I tried the third method, I get the error
    “Can’t open charmap file UTF-8: No such file or directory”. Any idea on how to fix this?

  • bs July 29, 2015, 5:47 pm

    Thanks!

  • dangors August 12, 2015, 10:58 am

    Hi thanks very much
    Method #2 worked for me but
    i did
    nano /etc/ssh_config to
    fix my error ; now i don’t have the problem again when i ssh into my remote machine.
    Thanks!

  • Omer September 14, 2015, 11:43 am

    option 3 worked. Thanks

  • EMM December 2, 2015, 5:34 am

    resolved…

  • Peter Evans December 7, 2015, 9:00 pm

    Thanks, Method #1 did the trick for me.

  • Armando G March 16, 2016, 12:40 pm

    Thanks man, option #1 works (El Capitan)

  • Manish Jaiswal May 9, 2016, 6:25 pm

    It worked thanks

  • Louis September 28, 2016, 2:13 am

    It works well. Thanks!

  • Paulo A. Nascimento October 23, 2016, 1:11 pm

    Hi, thanks for the article.
    I was facing this issue, not always, while connection to an EC2 Linux instance through macOS console app, and that small checkbox made all the difference.

  • jules January 4, 2017, 1:22 pm

    thanks for the clear explanation! bookmarked the site.

  • carlos bautista February 3, 2017, 4:38 pm

    Thanks Vivek, this is by far the best explanation to this issue I’ve found

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , ,