macOS terminal SSH locale

The macOS terminal defaults to UTF8. When SSHing into a macOS computer from a non-macOS computer, or any computer with a different locale, there may be problems running programs on the remote where locale is important. For example, a Linux system with “C” locale may cause .zip archive extraction on remote macOS to fail like:

Pathname cannot be converted from UTF-8 to current locale.

Locally on the macOS computer (or using Remote Desktop over SSH), check locale with:

% locale

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=

while from Windows or Linux may result in:

% locale

LANG=""
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

Fix

We resolved this issue by creating on the remote macOS computer a file “locale.sh” containing:

export LANG="en_US.UTF-8"
export LC_COLLATE="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_MESSAGES="en_US.UTF-8"
export LC_MONETARY="en_US.UTF-8"
export LC_NUMERIC="en_US.UTF-8"
export LC_TIME="en_US.UTF-8"

then run one time when needed:

source ~/locale.sh

This fixed an issue we had with CMake not extracting a .zip file for ExternalProject URL with the error noted at the top of this page.

Another workaround as noted above is to use Remote Desktop over SSH.