Setting locale failed 🐧 Linux

perl: warning: Setting locale failed / bash: warning: setlocale: LC_ALL: cannot change locale

Your session asks for a locale (often forwarded by SSH from your Mac/PC) that isn’t generated on the server.

Seen on: Linux

Meaning

SSH forwards LANG/LC_* variables. If the server doesn’t have that locale (e.g. en_IN.UTF-8 or a macOS default), perl, apt and bash print warnings. Generating the locale or not forwarding it fixes it.

Common causes

  • SSH client sends LC_* variables not available on the server
  • Locale not generated on a minimal server/container
  • LC_ALL set to an invalid value

⚡ Quick fix

  1. Generate the locale: sudo locale-gen en_US.UTF-8 && sudo update-locale
  2. Stop forwarding: remove SendEnv LANG LC_* on the client
  3. Set LANG=C.UTF-8 in containers

Detailed fix by platform

Ubuntu

  1. bash
    sudo locale-gen en_US.UTF-8
    sudo update-locale LANG=en_US.UTF-8
    locale

Dockerfile

  1. ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

How to diagnose

  1. Requested — locale output / env | grep LC_
  2. Available — locale -a

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.