Temporarily change language for terminal messages/warnings/errors
Solution 1:
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=
Solution 2:
Lekensteyn's helpful answer works great if you want to switch to US English on demand, as the OP requested, but if you want to switch to a different language on demand, more work is needed.
Before starting, you must install message tables with sudo apt-get install language-pack-<lang-tag>
, where <lang-tag>
is a simple RTF 5646 language subtag, such as es
for Spanish.
Background info
GNU gettext-based utilities give precedence to the nonstandard LANGUAGE
environment variable[1]
over POSIX-defined locale environment variables LC_ALL
, LC_MESSAGES
, and LANG
(in that order).
Given that LANGUAGE
is set by default on Ubuntu systems[2], namely to a substring of the LANG
value that reflects either a simple language tag (e.g., es
for Spanish) or a language-region tag (e.g., de_DE
for the Germany variant of German), you must unset or override LANGUAGE
in order for a different language's messages to take effect.[3]
Option 1: Set LANGUAGE
Example: Switch to Spanish (es
) messages ad-hoc:
$ LANGUAGE=es ls NoSuchFile
ls: no se puede acceder a NoSuchFile: No existe el archivo o el directorio
Note: A simple language tag such as es
is sufficient, but you may add a region identifier (e.g., es_AR
for Argentina), and even a charset suffix (e.g., es_AR.UTF-8
).
However, localized messages may only exist at the language level, and the fallback is to use messages that match the language part (es
, in this case).
Option 2: Unset LANGUAGE
and set LC_ALL
This alternative solution undefines LANGUAGE
first, and then uses POSIX locale environment variable LC_ALL
to implicitly set LC_MESSAGES
[4]:
$ LANGUAGE= LC_ALL=es_ES.UTF-8 ls NoSuchFile
ls: no se puede acceder a NoSuchFile: No existe el archivo o el directorio
This solution has the advantage of setting all localization aspects to the specified locale (such as LC_TIME
for date/time formats) and by (implicitly) setting LC_MESSAGES
also informs non-GNU programs of the desired language.
Note how LC_ALL
requires the exact, full locale name, including charset suffix, to be effective (es_ES.UTF-8
) (unlike LANGUAGE
, for which a simple language tag is sufficient (like es
)). The same applies to setting LC_MESSSAGES
and LANG
. Specifying an invalid / non-installed locale name causes fallback to the POSIX locale and therefore US English.