Connect to a Raspberry Pi from macOS

TLDR

In the macOS Terminal preferences, uncheck ‘Set locale environment variables on startup’ in the ‘Advanced’ tab of the ‘Profiles’ section.

Issue

Weird things happen when connecting with the macOS Terminal to a Raspberry Pi. For example running the command ‘curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh‘ for installing Docker throws errors. The script struggles because Perl has a problem with the localization. So I started digging in the dirt. When running the command ‘locale‘ to check the localization, I encountered an error message containing the phrase ‘Cannot set LC_CTYPE to default locale: No such file or directory‘.

pi@raspberrypi:~ $ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=
pi@raspberrypi:~ $ 

or

pi@raspberrypi:~ $ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
C
C.UTF-8
de_CH.utf8
en_GB.utf8
POSIX
pi@raspberrypi:~ $ 

Solution

Trying to set localization with ‘sudo raspi-config‘, ‘sudo dpkg-reconfigure locales‘ or by editing ‘/etc/locale.gen‘ and subsequently running ‘sudo locale-gen‘ did not lead to success. Finally, I found that a difference in the locale settings on the client (macOS) and the host Raspberry Pi causes conflicts and the observed issues.

Host (macOS) locale

Naiad:~ rolf$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

Client (Raspberry Pi) locale

pi@raspberrypi:~ $ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

Trick

The trick is now to not send the locale over SSH. This may be achieved by removing the ‘SendEnv LANG LC_*‘ in the ‘/etc/ssh/ssh_config‘ file.

An even easier way is to change the preferences of the macOS Terminal. To that end, uncheck ‘Set locale environment variables on startup’ in the ‘Advanced’ tab of the ‘Profiles’ section.

macOS Terminal settings: Uncheck ‘Set locale environment variables on startup’

Client (Raspberry Pi) locale after change

pi@raspberrypi:~ $ locale
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

References

Leave a Reply

Your email address will not be published. Required fields are marked *