Ubuntu系统修改Locale时出现错误的解决方法
时间:2023-02-21 18:50:28
众所周知,Ubuntu修改Locale的目的就是更改Linux系统的语言环境,但是Ubuntu修改Locale经常出现一个错误,导致出现中文乱码等一系列的问题。这是怎么回事呢?出现这样的问题如何解决呢?下面,就跟随小编一起来看看Ubuntu系统修改Locale时出现错误的解决方法。
Ubuntu
问题描述
终端显示中文正常,应用程序里面显示中文异常。
错误表现
1$ sudo dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = “zh_CN:zh:en_US:en”,
LC_ALL = “zh_CN.UTF-8”,
LANG = “zh_CN.UTF-8”
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”)。
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
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8)
Generating locales.。。
en_US.UTF-8.。。 /usr/sbin/locale-gen: line 177: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8)
up-to-date
Generation complete.
1$ man locale
man: can‘t set the locale; make sure $LC_* and $LANG are correct
1$ 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=zh_CN.UTF-8
LANGUAGE=zh_CN:zh:en_US:en
LC_CTYPE=“zh_CN.UTF-8”
LC_NUMERIC=“zh_CN.UTF-8”
LC_TIME=“zh_CN.UTF-8”
LC_COLLATE=“zh_CN.UTF-8”
LC_MONETARY=“zh_CN.UTF-8”
LC_MESSAGES=“zh_CN.UTF-8”
LC_PAPER=“zh_CN.UTF-8”
LC_NAME=“zh_CN.UTF-8”
LC_ADDRESS=“zh_CN.UTF-8”
LC_TELEPHONE=“zh_CN.UTF-8”
LC_MEASUREMENT=“zh_CN.UTF-8”
LC_IDENTIFICATION=“zh_CN.UTF-8”
LC_ALL=
1$ localectl list-locales
C.UTF-8
en_US.utf8
zh_CN.utf8
[page]
问题解决办法
要想达到应用程序中正常显示中文字符的目的,要下面的三个变量应该如下,
1LANG=zh_CN.UTF-8
2LANGUAGE=zh_CN:zh:en_US:en
3LC_ALL=LC_ALL=zh_CN.UTF-8
但问题在于“LC_ALL to default locale: No such file or directory”和“LC_ALL: cannot change locale (zh_CN.UTF-8) ”,因此重新安装中文语言包。
执行下面命令
1sudo apt-get -y install language-pack-zh-hans
或
1sudo apt-get -y install language-pack-zh-hans language-pack-zh-hans-base
如果想支持繁体字,则执行
1sudo apt-get -y install language-pack-zh-hant
或
1sudo apt-get -y install language-pack-zh-hant language-pack-zh-hant-base
再执行locale命令设置当前locale环境
1locale
相关的文件和参考
相关手册:man locale(1), locale(5), locale(7)
相关文件:/usr/share/i18n/SUPPORTED
相关命令:
locale --all-locales 列出当前系统中所有支持的locale
localectl list-locales 列出当前系统中所有可用的locale
localectl set-locales LOCALE.。。 修改当前系统中的locale,与locale功能相同,与export上文提到的三个变量相同
对于CentOS,可以直接编辑/etc/sysconfig/i18n文件,将LANG=“en_US.UTF-8”设置成LANG=“zh_CN.UTF-8”,除此之外,CentOS下locale命令的显示结果如下:
1# locale
LANG=en_US.UTF-8
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=
其中,LC_ALL=为空,但并不是表示这里不对,而是LC_ALL=实际上等于LC_COLLATE、LC_CTYPE、LC_MONETARY、LC_MESSAGES、LC_NUMERIC、LC_TIME,参见locale(7)。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Excel怎么插入雷达图
![](https://img.aspxhome.com/file/2023/4/54964_0s.gif)
win7电脑怎样设置文档显示数目?
![](https://img.aspxhome.com/file/2023/4/a310704_0s.jpg)
如何解决win10文件重命名后卡住死机的问题?
![](https://img.aspxhome.com/file/2023/3/46973_0s.png)
解答无法定位程序输入点于动态链接库advapi32.dll问题
![](https://img.aspxhome.com/file/2023/30/a267137_0s.png)
10 月 26 日更新macOS Monterey,看看你的 Mac在不在更新的兼容设备中
![](https://img.aspxhome.com/file/2023/5/a204325_0s.jpeg)
如何在excel工作簿不同工作表之间进行链接跳转?
![](https://img.aspxhome.com/file/2023/9/a161659_0s.jpg)
win10系统网络感叹号连不上网的解决方法分享
![](https://img.aspxhome.com/file/2023/3/47133_0s.png)
Win11打开注册表编辑器的八种方法介绍
![](https://img.aspxhome.com/file/2023/30/a268508_0s.jpg)
Win7进入安全模式卡住提示“加载disk.sys失败”怎么修复?
![](https://img.aspxhome.com/file/2023/27/a230999_0s.jpg)
wps文件未保存怎么恢复?
![](https://img.aspxhome.com/file/2023/3/a168633_0s.png)
win10开机黑屏只有鼠标箭头怎么修复
![](https://img.aspxhome.com/file/2023/1/a281481_0s.png)
打印机驱动安装完毕后打印机仍然不能打印怎么办?
![](https://img.aspxhome.com/file/2023/6/a322291_0s.png)
Win7系统下lol打字没有候选框的解决方法
![](https://img.aspxhome.com/file/2023/28/a242405_0s.jpg)
360快剪辑视频保存在哪里?
![](https://img.aspxhome.com/file/2023/30/a269530_0s.png)
Win10 1709预览版日历怎么添加球赛赛程提醒?
![](https://img.aspxhome.com/file/2023/28/a241756_0s.jpg)
XLOOKUP函数与VLOOKUP函数使用方法以及实例分析
![](https://img.aspxhome.com/file/2023/7/15077_0s.jpg)
Pr 入门教程「53」如何匹配场景中的剪辑颜色?
![](https://img.aspxhome.com/file/2023/9/a203589_0s.jpeg)
Win7系统如何使用Shutdown.exe程序快速定时关机?
![](https://img.aspxhome.com/file/2023/28/a243965_0s.jpg)
win10是不是容易蓝屏?win10容易蓝屏解决教程
![](https://img.aspxhome.com/file/2023/5/48065_0s.jpg)
win10开机Default Boot Device Missing or Boot Failed错误怎么办
![](https://img.aspxhome.com/file/2023/2/a288493_0s.gif)