linux禁用locale警告修复
AI-摘要
切换
Tianli GPT
AI初始化中...
介绍自己
生成本文简介
推荐相关文章
前往主页
前往tianli博客
一、问题
登录时报错环境变量目录找不到
系统中仍有配置文件(如
/etc/locale.conf)强制设置LANG=en_US.UTF-8,优先级高于/etc/profile;即使手动
export LC_ALL=C,系统仍会先读取/etc/locale.conf的配置,导致locale命令仍加载不存在的en_US.UTF-8;
Welcome to Alibaba Cloud Elastic Compute Service !
-bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_COLLATE: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_MESSAGES: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_NUMERIC: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8): No such file or directory
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)二、修复方法
# 1. 强制清空当前会话的locale变量,设置为内置C(立即生效)
unset LC_ALL
unset LANG
export LC_ALL=C
export LANG=C
# 2. 覆盖/etc/locale.conf(系统级locale配置,优先级最高)
echo "LANG=C" > /etc/locale.conf
echo "LC_ALL=C" >> /etc/locale.conf
# 3. 覆盖/etc/profile的locale配置(全局登录生效)
sed -i '/LC_ALL=en_US.UTF-8/d' /etc/profile
sed -i '/LANG=en_US.UTF-8/d' /etc/profile
echo "export LC_ALL=C" >> /etc/profile
echo "export LANG=C" >> /etc/profile
# 4. 覆盖当前用户的.bashrc(登录会话生效)
sed -i '/LC_ALL=en_US.UTF-8/d' ~/.bashrc
sed -i '/LANG=en_US.UTF-8/d' ~/.bashrc
echo "export LC_ALL=C" >> ~/.bashrc
echo "export LANG=C" >> ~/.bashrc
# 5. 立即加载新配置,无需重启
source /etc/locale.conf
source /etc/profile
source ~/.bashrc
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
作者编辑不易,如有转载请注明出处。完整转载来自https://wangairui.com 网站名称:猫扑linux
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果

