The Terminal program in MacOS has a bug in its handling of the ‘locale’. It has been there for a long time and is still present in version 2.13 in MacOS 13.2 (Ventura).
By default, Terminal sets various environment related to the
locale. When you type locale
, you should see
something like:
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
These variables determine such things as the language of error messages and the sort order of file names. The value should consist of a language code (‘en’ in the example above, meaning English), a region code (‘US’) and an optional character encoding (‘UTF-8”).
By default, when Terminal starts a new window or tab, it sets
these variables. Unfortunately, it sets the LC_CTYPE variable
incorrectly. It omits the language and region and just sets it
to the character encoding: LC_CTYPE=UTF-8
. Not all
programs use this variable and the programs that do under MacOS
mostly seem to deal with it but you can notice the problems when
you login to a machine that does not run MacOS. E.g., when you
ssh to a Linux machine and start perl, it will issue a warning
(and use the LANG variable instead of LC_CTYPE):
warning: Setting locale failed.
The workaround is to tell Terminal to not set these variables. It is not necessary for Terminal to set them anyway, because they are already set by MacOS.
You can configure Terminal by going to Terminal → Settings, then to the Profiles tab and then the Advanced tab. At the bottom, under ‘International’, uncheck the line that says ‘Set locale environment variables at startup’
The relevant setting is indicated by the red oval.