How to solve the "WARNING! Your environment specifies an invalid locale" Error

On logging into a remote server, I got an error that began with: WARNING! Your environment specifies an invalid locale.. This is how I fixed it:

I entered each one of these commands in the terminal. The last one reboots the server.

  1. locale
  2. export LANGUAGE=en_US.UTF-8; export LANG=en_US.UTF-8; export LC_ALL=en_US.UTF-8; locale-gen en_US.UTF-8
  3. sudo dpkg-reconfigure locales
  4. sudo shutdown -r 0

Read more here.