Ubuntu – Temporarily change language for terminal messages/warnings/errors

command linelanguagelocale

Messages in my terminal are displayed using Russian language by default, which is my native one.

For just a moment I want them to be in English (eg. to paste in forums), then switch back to the default language.

How can I do the switch and switch back using bash?

Best Answer

There are several environment variables available for changing language settings. You can view your current locale settings by executing the locale command. To change all locale settings to English, use LANG=C. This C locale is always available without installing additional language packs. (In order to temporarily change to non-English locales, see @mklement0's post.)

Examples:

Executing a command with the default language settings and print the current locale settings:

$ /nonexistent
bash: /nonexistent: Bestand of map bestaat niet
$ locale
LANG=nl_NL.UTF-8
LANGUAGE=
LC_CTYPE="nl_NL.UTF-8"
LC_NUMERIC="nl_NL.UTF-8"
LC_TIME="nl_NL.UTF-8"
LC_COLLATE="nl_NL.UTF-8"
LC_MONETARY="nl_NL.UTF-8"
LC_MESSAGES="nl_NL.UTF-8"
LC_PAPER="nl_NL.UTF-8"
LC_NAME="nl_NL.UTF-8"
LC_ADDRESS="nl_NL.UTF-8"
LC_TELEPHONE="nl_NL.UTF-8"
LC_MEASUREMENT="nl_NL.UTF-8"
LC_IDENTIFICATION="nl_NL.UTF-8"
LC_ALL=

Temporarily override the language for one program and show that it is really temporary:

$ LANG=C ls /nonexistent
ls: cannot access /nonexistent: No such file or directory
$ ls /nonexistent
ls: kan geen toegang krijgen tot /nonexistent: Bestand of map bestaat niet

Change the locale for all commands executed in the current shell and include proofs again:

$ LANG=C
$ ls /nonexistent
ls: cannot access /nonexistent: No such file or directory
$ locale
LANG=C
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=