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.
Infrastructure locale linuxWhen 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
-
Log in as root, or as a user with administrative rights.
-
Open
/etc/environmentin an editor such as vim or nano and add:LC_CTYPE=en_US.UTF-8 -
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.