Ubuntu系统安装后的20项必备优化设置指南
1. Ubuntu 安装后的基础优化设置作为一名使用Ubuntu超过8年的老用户我深知刚安装完系统后那些看似微小却影响深远的设置调整。这些设置能让你的Ubuntu系统从能用变成好用特别是对于刚从Windows转过来的新手。下面这些设置都是我多年实战总结的精华建议按顺序操作。1.1 更换国内软件源刚安装好的Ubuntu默认使用国外软件源更新和安装软件速度极慢。将软件源更换为国内镜像源是最优先的操作sudo sed -i s|http://.*archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g /etc/apt/sources.list sudo sed -i s|http://.*security.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g /etc/apt/sources.list sudo apt update sudo apt upgrade -y这里我推荐清华源实测速度稳定。操作后会立即感受到apt命令的速度提升。注意Ubuntu不同版本(如20.04/22.04)的源地址可能略有不同如果遇到404错误可以去清华源官网查看对应版本的配置。提示执行完记得运行sudo apt update刷新软件列表否则更改不会生效1.2 安装必要的基础工具Ubuntu最小化安装会缺少一些常用工具建议先安装这些基础包sudo apt install -y vim git curl wget net-tools htop tree unzip build-essentialvim比nano更强大的文本编辑器git版本控制工具curl/wget网络请求工具net-tools包含ifconfig等网络工具htop增强版系统监控工具tree以树状图列出目录结构build-essential编译工具链1.3 设置静态IP有线网络如果你使用有线连接且需要固定IP可以这样设置sudo nano /etc/netplan/00-installer-config.yaml修改为以下内容根据你的网络环境调整network: ethernets: enp3s0: dhcp4: no addresses: [192.168.1.100/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] version: 2应用配置sudo netplan apply注意网卡名称enp3s0需要用ip a命令查看你实际的网卡名称2. 系统性能与外观优化2.1 禁用不必要的启动项Ubuntu默认会启动一些不必要的服务拖慢系统速度sudo systemctl disable bluetooth.service sudo systemctl disable cups.service sudo systemctl disable avahi-daemon.service可以通过systemctl list-unit-files --typeservice | grep enabled查看所有启用的服务按需禁用。2.2 安装GNOME优化工具GNOME Tweaks是调整Ubuntu外观和行为的利器sudo apt install -y gnome-tweaks安装后可以更改主题、图标和光标调整字体和缩放比例管理扩展程序修改窗口控制按钮位置2.3 启用夜灯模式长时间盯着屏幕容易眼疲劳夜灯模式可以减少蓝光gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled true gsettings set org.gnome.settings-daemon.plugins.color night-light-temperature 3500可以在设置中调整色温和启用时间。3. 中文环境与输入法配置3.1 安装中文语言包sudo apt install -y language-pack-zh-hans sudo apt install -y $(check-language-support -l zh_CN)然后打开Settings → Region Language添加中文(China)并拖到第一位。3.2 安装搜狗输入法虽然Ubuntu自带ibus输入法但搜狗体验更好sudo apt install -y fcitx wget https://cdn2.ime.sogou.com/dl/index/1649737394/sogoupinyin_2.4.0.3469_amd64.deb sudo dpkg -i sogoupinyin_2.4.0.3469_amd64.deb sudo apt --fix-broken install安装后需要重启系统打开Fcitx配置添加搜狗拼音在Settings → Region Language中将输入法改为Fcitx常见问题如果遇到依赖错误先运行sudo apt --fix-broken install再重试4. 开发环境基础配置4.1 安装Python和pipUbuntu预装Python3但需要单独安装pipsudo apt install -y python3-pip sudo pip3 install --upgrade pip设置pip国内源加速mkdir -p ~/.pip echo -e [global]\nindex-url https://pypi.tuna.tsinghua.edu.cn/simple ~/.pip/pip.conf4.2 安装VS Code推荐使用官方仓库安装最新版VS Codewget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor packages.microsoft.gpg sudo install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/ sudo sh -c echo deb [archamd64 signed-by/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main /etc/apt/sources.list.d/vscode.list sudo apt update sudo apt install -y code安装后建议安装以下扩展Chinese (Simplified) Language PackPythonPylanceDockerESLint4.3 配置Gitgit config --global user.name Your Name git config --global user.email your.emailexample.com git config --global core.editor vim git config --global credential.helper store生成SSH密钥ssh-keygen -t rsa -b 4096 -C your.emailexample.com cat ~/.ssh/id_rsa.pub将公钥添加到GitHub/GitLab等平台。5. 硬件相关优化5.1 安装NVIDIA显卡驱动如果你使用NVIDIA显卡官方开源驱动性能较差sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update ubuntu-drivers devices sudo apt install -y nvidia-driver-525安装后需要重启。可以通过nvidia-smi命令验证驱动是否正常工作。5.2 调整交换分区(swap)大小Ubuntu默认的交换分区大小可能不够特别是内存小于8GB时sudo swapoff -a sudo dd if/dev/zero of/swapfile bs1G count8 sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile将以下内容添加到/etc/fstab使更改永久生效/swapfile none swap sw 0 05.3 优化电源管理笔记本用户需要优化电源设置sudo apt install -y tlp tlp-rdw sudo systemctl enable tlpTLP会自动优化CPU频率调节硬盘高级电源管理WiFi省电模式显卡电源管理6. 安全增强设置6.1 配置UFW防火墙Ubuntu默认防火墙是关闭的sudo ufw enable sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow ssh sudo ufw allow http sudo ufw allow https6.2 禁用root登录SSH编辑SSH配置文件sudo nano /etc/ssh/sshd_config找到并修改以下行PermitRootLogin no PasswordAuthentication no然后重启SSH服务sudo systemctl restart sshd6.3 设置自动安全更新sudo apt install -y unattended-upgrades sudo dpkg-reconfigure -plow unattended-upgrades这会让系统自动安装安全更新保持系统安全。7. 实用工具推荐7.1 安装Dockersudo apt install -y apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository deb [archamd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable sudo apt update sudo apt install -y docker-ce sudo usermod -aG docker $USER7.2 安装Timeshift系统备份Timeshift相当于Windows的系统还原点sudo apt install -y timeshift首次运行建议选择RSYNC模式设置定期自动备份。7.3 安装Stacer系统优化工具Stacer是Ubuntu上的电脑管家sudo add-apt-repository ppa:oguzhaninan/stacer sudo apt update sudo apt install -y stacer可以清理垃圾文件、管理启动项、监控资源等。8. 个性化定制技巧8.1 安装扩展管理器sudo apt install -y gnome-shell-extension-manager通过它可以方便地安装和管理GNOME扩展比如Dash to Panel将顶栏和dock合并Arc MenuWindows风格的开始菜单Clipboard Indicator剪贴板历史记录8.2 自定义GRUB启动菜单编辑GRUB配置sudo nano /etc/default/grub修改以下参数GRUB_TIMEOUT3 # 启动菜单等待时间 GRUB_CMDLINE_LINUX_DEFAULTquiet splash # 添加nomodeset可解决某些显卡问题更新GRUBsudo update-grub8.3 安装Conky系统监视器Conky可以在桌面显示系统信息sudo apt install -y conky-all cp /etc/conky/conky.conf ~/.conkyrc nano ~/.conkyrc网上有很多现成的.conkyrc配置可以下载使用。完成以上设置后你的Ubuntu系统应该已经脱胎换骨。这些设置涵盖了从基础配置到开发环境从性能优化到安全加固的各个方面。根据我的经验做好这些设置可以避免日后使用中80%的常见问题。当然Ubuntu的魅力在于它的可定制性你可以继续探索更多个性化设置来打造专属的工作环境。