中国用户首次配置
本文面向中国大陆用户,汇总了 Ubuntu 26.04 安装后需要完成的一系列本地化配置。按照以下步骤操作,可以快速将系统调整到适合国内使用的状态。
更换国内镜像源
Ubuntu 默认软件源服务器位于海外,国内访问速度较慢。更换为国内镜像可以大幅提升软件安装和更新速度。
推荐镜像源
| 镜像站 | 地址 | 说明 |
|---|---|---|
| 阿里云 | mirrors.aliyun.com | 稳定快速,推荐大多数用户 |
| 清华大学 | mirrors.tuna.tsinghua.edu.cn | 教育网用户首选 |
| 中科大 | mirrors.ustc.edu.cn | 教育网用户推荐 |
修改方法
Ubuntu 26.04 使用 DEB822 格式的源配置文件:
# 备份原始源配置
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak
# 使用 sed 替换为阿里云镜像
# (cn\.)? 同时兼容 cn.archive.ubuntu.com 和 archive.ubuntu.com,避免生成无效域名
# 只替换主机名,http/https 协议保持不变
sudo sed -i -E 's|(cn\.)?archive.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list.d/ubuntu.sources
sudo sed -i -E 's|security.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list.d/ubuntu.sources
# 如果使用清华源,替换命令如下:
# sudo sed -i -E 's|(cn\.)?archive.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources
# sudo sed -i -E 's|security.ubuntu.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources
# 如果使用中科大源:
# sudo sed -i -E 's|(cn\.)?archive.ubuntu.com|mirrors.ustc.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources
# sudo sed -i -E 's|security.ubuntu.com|mirrors.ustc.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources
# 更新软件包索引
sudo apt update如果你在安装 Ubuntu 时选择了中国时区,安装程序可能已经自动配置了 cn.archive.ubuntu.com,但该地址速度不一定最优。建议手动替换为上述镜像站。
安装中文语言包
安装完整的中文语言支持,确保系统界面、日期格式、排序规则等全部中文化。
# 安装中文语言包
sudo apt install language-pack-zh-hans language-pack-gnome-zh-hans -y
# 生成中文 locale
sudo locale-gen zh_CN.UTF-8
# 设置系统默认语言为中文
sudo update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh
# 注销并重新登录使设置生效如果你希望保留英文界面但使用中文输入法,可以跳过 update-locale 步骤,仅安装语言包即可。
配置中文输入法
Ubuntu 26.04 推荐使用 Fcitx5 输入法框架,搭配中文输入法引擎。
安装 Fcitx5
# 安装 Fcitx5 核心和中文输入法引擎
sudo apt install fcitx5 fcitx5-chinese-addons fcitx5-frontend-gtk3 fcitx5-frontend-gtk4 fcitx5-frontend-qt5 -y
# 安装配置工具
sudo apt install fcitx5-config-qt -y设置为默认输入法
# 将 Fcitx5 设为默认输入法框架
im-config -n fcitx5配置环境变量
在 26.04 的 Wayland 图形会话下,多数情况下 im-config -n fcitx5 已经足够,输入法环境变量由 im-config 自动处理,通常无需手动设置。把变量写入 ~/.bashrc 对 GNOME 图形会话也无效(图形会话不会读取 ~/.bashrc)。仅当个别应用无法输入中文时,才按下面的方式手动设置。
如果确实需要手动设置,请写入对系统图形会话生效的 /etc/environment:
# 将输入法环境变量写入 /etc/environment(对图形会话生效)
sudo tee -a /etc/environment << 'EOF'
# Fcitx5 输入法环境变量
XMODIFIERS=@im=fcitx
QT_IM_MODULE=fcitx
# Wayland 下 GTK 应用通常无需设置 GTK_IM_MODULE;
# 仅当某些 GTK 应用无法输入时再取消下一行注释
# GTK_IM_MODULE=fcitx
EOF注销并重新登录后,在系统托盘中找到 Fcitx5 图标,右键点击选择”配置”,添加”拼音”输入法。默认使用 Ctrl+Space 切换中英文。
如果你更习惯使用搜狗输入法或其他第三方输入法,可以前往其官网下载 Linux 版本的 .deb 安装包。但 Fcitx5 自带的拼音输入法已经非常好用,支持云拼音、词库导入等功能,建议先试用。
安装中文字体
Ubuntu 默认的中文字体覆盖不够全面,建议安装以下字体包:
# 安装 Noto CJK 字体(Google 出品,覆盖中日韩全部字符)
sudo apt install fonts-noto-cjk fonts-noto-cjk-extra -y
# 安装文泉驿字体
sudo apt install fonts-wqy-microhei fonts-wqy-zenhei -y
# 刷新字体缓存
fc-cache -fv安装完成后,可以在”设置 - 外观”中选择喜欢的中文字体。
设置时区
如果安装时未正确选择时区,可以手动设置:
# 查看当前时区
timedatectl
# 设置为上海时区(中国标准时间)
sudo timedatectl set-timezone Asia/Shanghai
# 确认时区已更改
date如果是 Windows 和 Ubuntu 双系统,可能会遇到时间不同步的问题。解决方法:
# 让 Ubuntu 将硬件时钟视为本地时间(与 Windows 保持一致)
sudo timedatectl set-local-rtc 1安装常用软件
浏览器
# Firefox 已预装(Snap 版本)
# 安装 Google Chrome
wget -q -O /tmp/chrome.deb "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
sudo apt install /tmp/chrome.deb -y办公软件
# LibreOffice 已预装,安装中文语言包
sudo apt install libreoffice-l10n-zh-cn -y
# 安装 WPS Office(从官网下载 .deb 包)
# 访问 https://linux.wps.cn/ 下载后安装
# sudo apt install ./wps-office_*.deb -y聊天工具
# 安装微信(Snap 版)
sudo snap install wechat-universal
# 安装 QQ(从官网下载)
# 访问 https://im.qq.com/linuxqq/ 下载 .deb 包
# sudo apt install ./linuxqq_*.deb -y音视频
# 安装 VLC 媒体播放器
sudo apt install vlc -y
# 安装多媒体编解码器
sudo apt install ubuntu-restricted-extras -y安装 ubuntu-restricted-extras 时会弹出 EULA 协议确认界面,使用 Tab 键选择”确定”并按 Enter 键确认。
网络环境配置
Git 配置国内加速
# 使用 GitHub 镜像(如果直连 GitHub 速度慢)
git config --global url."https://ghfast.com/https://github.com/".insteadOf "https://github.com/"npm 镜像
# 设置 npm 使用淘宝镜像
npm config set registry https://registry.npmmirror.compip 镜像
# 设置 pip 使用清华镜像
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn系统代理设置
如果需要配置 HTTP 代理:
# 临时设置(当前终端有效)
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
# 永久设置(写入 ~/.bashrc)
cat >> ~/.bashrc << 'EOF'
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
export no_proxy="localhost,127.0.0.1,192.168.0.0/16"
EOF也可以在”设置 - 网络 - 网络代理”中通过图形界面配置。
一键命令汇总
以下命令汇总了本文所有关键操作,你可以按需复制执行。建议逐步运行而非一次全部粘贴,以便观察每一步的输出是否正常。
# 1. 更换镜像源(以阿里云为例,(cn\.)? 同时兼容 cn.archive.ubuntu.com)
sudo sed -i -E 's|(cn\.)?archive.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list.d/ubuntu.sources
sudo sed -i -E 's|security.ubuntu.com|mirrors.aliyun.com|g' /etc/apt/sources.list.d/ubuntu.sources
sudo apt update
# 2. 安装中文语言包
sudo apt install language-pack-zh-hans language-pack-gnome-zh-hans -y
sudo locale-gen zh_CN.UTF-8
sudo update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh
# 3. 安装中文输入法
sudo apt install fcitx5 fcitx5-chinese-addons fcitx5-frontend-gtk3 fcitx5-frontend-gtk4 fcitx5-frontend-qt5 fcitx5-config-qt -y
im-config -n fcitx5
# 4. 安装中文字体
sudo apt install fonts-noto-cjk fonts-noto-cjk-extra fonts-wqy-microhei fonts-wqy-zenhei -y
fc-cache -fv
# 5. 设置时区
sudo timedatectl set-timezone Asia/Shanghai
# 6. 安装常用软件
sudo apt install vlc ubuntu-restricted-extras libreoffice-l10n-zh-cn -y
wget -q -O /tmp/chrome.deb "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
sudo apt install /tmp/chrome.deb -y
# 7. 配置开发工具镜像(按需)
# npm config set registry https://registry.npmmirror.com
# pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple完成以上配置后,注销并重新登录即可享受完整的中文 Ubuntu 体验。