无法设置区域设置 Ubuntu 16.04

无法设置区域设置,就是这样。我的VPS给了我一个损坏的Ubuntu 16.04发行版:


$ export LC_ALL="en_US.UTF-8"

-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

$ locale -a

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
C.UTF-8
POSIX

$ locale

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

$ sudo locale-gen "en_US.UTF-8"

sudo: locale-gen: command not found

$ sudo apt-get install locale-gen

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package locale-gen

我的选择有哪些?

关于Gunnar的更新:

$ sudo apt install --reinstall locales
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0 B/3213 kB of archives.
After this operation, 0 B of additional disk space will be used.
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76, <> line 1.)
debconf: falling back to frontend: Readline
Preconfiguring packages ...
(Reading database ... 27980 files and directories currently installed.)
Preparing to unpack .../locales_2.23-0ubuntu10_all.deb ...
Unpacking locales (2.23-0ubuntu10) over (2.23-0ubuntu10) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up locales (2.23-0ubuntu10) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Generating locales (this might take a while)...
Generation complete.

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

$ sudo locale-gen "en_US.UTF-8"
Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.

$ export LC_ALL="en_US.UTF-8"
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

你是否安装了"locales"包? - Sebastian Stark
是的,我已经安装了。 - Soy Boys Beware
那你应该有locale-gen程序。你能检查一下你的PATH变量吗? - Sebastian Stark
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games - Soy Boys Beware
奇怪。尝试sudo apt install --reinstall locales - Gunnar Hjalmarsson
好的,至少现在已经生成了en_US.UTF-8。无法解释您在尝试导出LC_ALL时遇到的错误。另一方面,为什么要这样做呢?看起来LANG已设置为en_US.UTF-8,应该足够了。(顺便说一下,也许您应该尝试重新登录/重启一下系统。) - Gunnar Hjalmarsson
Gunnar,我只想使用pip3来安装Python包,但是没有正确配置的区域设置是不可能的。还有其他的想法吗? - Soy Boys Beware
export LC_ALL=C应该总是有效的,你可以试一下吗? - Sebastian Stark
2个回答

那些步骤很有效。

apt-get update
apt-get install -y locales
locale-gen "en_US.UTF-8"
update-locale LC_ALL="en_US.UTF-8"

退出并重新登录。
export LC_ALL=en_US.UTF-8

这对我在18.04版本上也有效。 - jdhildeb
我将导出添加到~/.bashrc文件中。 - Andrew

首先,验证您的 locate 是否已安装,列出当前的 locate:
locale -a

如果您的位置未安装,请使用以下命令进行安装:
sudo dpkg-reconfigure locales

然后设置您的位置:
export LC_ALL=en_US.UTF-8