CentOS 7: How to Fix “cannot change locale (UTF-8)”

When remotely connecting to CentOS/RedHat Linux, it is very common to see a setlocale error if your SSH client (such as Terminal or iTerm) is using UTF-8 encoding. While this warning message is mostly harmless, it can cause confusion and nuisance when performing actions on the web host. Here’s a way how to get rid of the “cannot change locale (UTF-8)” warning message.

-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
 perl: warning: Setting locale failed.
 perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LC_CTYPE = "UTF-8",
 LANG = "en_US.UTF-8"
 are supported and installed on your system.
 perl: warning: Falling back to the standard locale ("C").
 perl: warning: Setting locale failed.
 perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LC_CTYPE = "UTF-8",
 LANG = "en_US.UTF-8"
 are supported and installed on your system.
 perl: warning: Falling back to the standard locale ("C").

If your terminal client has been set to UTF-8, you will most likely get this error messages after remotely ssh into the server.

The error is not only in terminal, it’s possible appear when compiling stuff in Perl or Python as well, or when installing software packages.

To fix the error above, open the file /etc/environment (nano etc/environment) and add this line to the file:

LC_CTYPE="en_US.UTF-8"

Leave a Reply

Your email address will not be published. Required fields are marked *