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

Logging in over SSH from a Mac to a CentOS server prints a setlocale LC_CTYPE warning. Setting LC_CTYPE in /etc/environment and generating the locale fixes it.

When I logged in over SSH from macOS to a CentOS server, every session started with this warning:

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

The fix takes two steps on the server.

The fix

  1. Log in as root, or as a user with administrative rights.

  2. Open /etc/environment in an editor such as vim or nano and add:

    LC_CTYPE=en_US.UTF-8
  3. Save the file and generate the locale:

    localedef -i en_US -f UTF-8 en_US.UTF-8

The warning no longer appears on new SSH sessions.

A word on CentOS

If you are still on CentOS Linux, consider moving to a distribution with long-term support. CentOS Stream is a rolling release, which may not suit servers that need stability. AlmaLinux and Rocky Linux are both free replacements built for that.

Join the discussion

Comments are hosted on comments.vciso.ch, a server I run myself. Nothing is loaded from it until you press the button below. Loading comments connects your browser to that server, and signing in with GitHub sets a cookie there. See the privacy page for details.

Type to search.

↑ ↓ to move, Enter to open, Esc to close