Resolving warning “LC_CTYPE” UTF-8
Fixing that irritating issue
As a MacOS user, it can be quite frustrating to encounter unexpected errors while logging in via SSH on a CentOS server. One such error is the “-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory” message. In this wansec post, we will explore a straightforward solution to fix this error and restore fluidity to your SSH sessions on MacOS.
Context around this error
While logging in via SSH to my CentOS system, I was confronted with the error message: “-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory.” Determined to resolve the issue, I embarked on finding a practical solution.
The simple solution
To fix the “LC_CTYPE” error on CentOS, follow these simple steps:
- Log in to your CentOS system with administrative privileges or switch to the root user.
- Open the
/etc/environment
file using your favorite text editor such as vim or nano - Add the following line to the file:
LC_CTYPE=en_US.UTF-8
- Save file and exit the text editor
- Generate the locale on your system
localedef -i en_US -f UTF-8 en_US.UTF-8
Conclusion
As we have seen, this error can be quickly resolved on CentOS by editing the /etc/environment
file, adding the appropriate locale configuration, and generating the locale. Following these simple steps, you can eliminate the error message and enjoy uninterrupted SSH sessions on your CentOS system.
Word of advice
If you haven’t upgraded your CentOS Linux to a stable distribution, it might be worth considering a switch to a more enterprise-oriented Linux distribution. While CentOS Stream provides a rolling-release model, you may prefer the reliability and long-term support offered by enterprise-grade distributions.
One such option is AlmaLinux, which serves as a free and robust replacement for CentOS. With AlmaLinux, you can enjoy the benefits of a stable and well-supported Linux distribution, ensuring the longevity and reliability of your server infrastructure. RockyLinux is another option.