How to solve 'unsupported locale setting' error

Here is how to solve the unsupported locale setting error on Ubuntu.

Example error in Perl:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "it_IT.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.

Example error in Python:

locale.Error: unsupported locale setting

Solution

echo "LANG=en_US.utf-8" >> /etc/environment
echo "LC_ALL=en_US.utf-8" >> /etc/environment