Ubuntu 26.04 LTS 安装后必做8项优化
1. Ubuntu 26.04 LTS 安装后必做8件事
刚装完Ubuntu系统就像搬进毛坯房,基础功能都有但用着总不顺手。作为从Ubuntu 12.04用到26.04的老用户,我总结出这套开箱必做的8项调优,20分钟就能让系统脱胎换骨。这些配置不仅提升使用流畅度,更能避免日后开发时遇到的坑。
1.1 更换国内软件源
新系统默认使用国外源,更新速度慢如蜗牛。打开终端(Ctrl+Alt+T)执行:
sudo sed -i 's|http://.*archive.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list sudo apt update && sudo apt upgrade -y这里用阿里云源举例,其他推荐源还有:
- 清华源:https://mirrors.tuna.tsinghua.edu.cn
- 中科大源:https://mirrors.ustc.edu.cn
注意:企业内网需先配置代理才能访问外网源,建议咨询IT部门获取内部源地址
更新完成后运行apt list --upgradable检查,应该显示"Listing... Done"而非具体包名,说明所有更新已安装。
1.2 安装必备工具链
开发环境的基础依赖一个都不能少:
sudo apt install -y build-essential git curl wget vim net-tools- build-essential:包含gcc/g++/make等编译工具
- git:代码版本管理
- curl/wget:网络请求工具
- vim:终端编辑器(nano党可替换)
- net-tools:包含ifconfig等网络工具
验证gcc安装:gcc --version应显示版本号≥11.4.0(26.04默认版本)
1.3 配置中文输入法
Ubuntu自带ibus输入框架但词库贫乏,推荐安装搜狗输入法:
sudo apt install -y fcitx libfcitx-qt5 libfcitx-qt6 wget https://ime.sogoucdn.com/dl/index/1793083180/sogoupinyin_4.2.1.145_amd64.deb sudo dpkg -i sogoupinyin_*.deb sudo apt --fix-broken install安装后需:
- 打开Settings → Region & Language → Manage Installed Languages
- 将Keyboard input method system改为fcitx
- 注销后重新登录
- 在顶部栏fcitx图标中添加Sogou Pinyin
常见问题:如果候选框不显示,执行
fcitx-autostart并检查~/.xprofile是否包含export GTK_IM_MODULE=fcitx
1.4 优化终端环境
默认bash功能有限,建议配置:
# 安装zsh和插件 sudo apt install -y zsh autojump sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting # 修改~/.zshrc配置 plugins=(git zsh-autosuggestions zsh-syntax-highlighting autojump) ZSH_THEME="agnoster"配置完成后:
- 按Tab键触发自动补全
- 输入命令前缀后按↑键搜索历史命令
- 输入目录名直接跳转(如
/usr/l按Tab补全)
1.5 显卡驱动安装
NVIDIA显卡用户务必安装闭源驱动:
ubuntu-drivers devices # 查看推荐驱动版本 sudo apt install -y nvidia-driver-550 # 以550版本为例安装后验证:
- 执行
nvidia-smi查看显卡状态 - 运行
glxinfo | grep "OpenGL renderer"确认驱动生效
避坑指南:如果遇到登录循环,Ctrl+Alt+F3切到命令行执行
sudo apt purge nvidia-*重装
1.6 配置SSH服务
远程开发必备:
sudo apt install -y openssh-server sudo systemctl enable --now ssh关键安全配置(/etc/ssh/sshd_config):
PermitRootLogin no PasswordAuthentication no # 推荐用密钥登录 AllowUsers yourname生成密钥对:ssh-keygen -t ed25519,将~/.ssh/id_ed25519.pub内容添加到服务器authorized_keys
1.7 安装Docker引擎
容器化开发环境基础:
sudo apt install -y ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io非root用户使用docker:
sudo usermod -aG docker $USER newgrp docker # 立即生效验证安装:docker run hello-world应显示欢迎信息
1.8 系统性能调优
最后这些隐藏设置能显著提升流畅度:
# 禁用不必要的服务 sudo systemctl disable bluetooth.service cups-browsed.service # 调整交换分区策略 echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf # 提升文件打开数限制 echo '* soft nofile 65535' | sudo tee -a /etc/security/limits.conf echo '* hard nofile 65535' | sudo tee -a /etc/security/limits.conf # 启用TRIM(SSD专用) sudo systemctl enable fstrim.timer使用gnome-tweaks工具还可:
- 关闭窗口动画
- 设置合盖不休眠
- 启用"Always On Top"右键菜单
2. 进阶配置建议
完成基础优化后,这些可选配置能让体验更上一层楼:
2.1 开发环境配置
Python环境建议用miniconda管理:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda echo 'export PATH="$HOME/miniconda/bin:$PATH"' >> ~/.zshrcVS Code必备插件:
- Remote - SSH
- Python
- Docker
- GitLens
2.2 硬件外设支持
打印机配置:
sudo apt install -y printer-driver-gutenprint system-config-printer # 图形化添加打印机蓝牙设备问题排查:
sudo dmesg | grep -i blue hciconfig -a # 查看蓝牙适配器状态2.3 系统监控方案
安装图形化监控工具:
sudo apt install -y gnome-system-monitor htop终端监控推荐:
btop:现代化资源监视器nvtop:NVIDIA显卡监控iotop:磁盘IO监控
3. 常见问题速查表
| 问题现象 | 解决方案 |
|---|---|
| 开机卡在紫色界面 | 在GRUB界面按e编辑启动参数,在linux行末尾加nomodeset |
| 双系统时间错误 | sudo timedatectl set-local-rtc 1 |
| 无法挂载NTFS分区 | sudo apt install ntfs-3g后重新插拔 |
| 触摸板失灵 | sudo modprobe -r psmouse && sudo modprobe psmouse |
| 耳机没有声音 | alsamixer中取消Auto-Mute |
这些优化是我在五台不同设备上实测有效的配置方案,特别适合需要稳定开发环境的用户。刚开始用Linux可能会觉得繁琐,但一旦配置完成,Ubuntu 26.04的稳定性和性能绝对值得这份投入。
