perl: warning: Setting locale failed. – Fixed

Getting warning about “setting locale failed” while executing Perl on CentOS ?

[root@lab program]# ./nikto.pl -h $IPADDRESS
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 a fallback locale ("en_US.UTF-8").
[root@lab program]#

It Cpanel server I used SSH terminal to connect from macOS. If you are encountering this error, here is how you can fix.

Solution

Export the following locale on your terminal and run the program.

export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

It ran smoothly to me and hope it helps you too.

This is fine if you just need to do one time. However, if you need to run it periodically then you may want to set this in profile so it loads during logon.

  • Go to the user’s home directory
  • Modify .bash_profile (assuming you are using bash) using vi
  • Add the following and save the file
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

That’s all!

Now, I can run Perl 😊