如何优化 Ubuntu 20.04 LTS 的性能和功能?

本文将详细介绍 Ubuntu 20.04 LTS 的最佳配置指南,从系统设置到软件安装,以及命令行工具和桌面美化等方面,帮助用户充分发挥 Ubuntu 的潜力。本文不仅仅是操作指南,还包含了背后的技术原理,帮助你更好地理解每个配置步骤的意义。


一. 系统配置

1. 关闭 sudo 密码

为了避免每次使用 sudo 命令时都输入密码,我们可以将密码关闭。操作方法如下:

sudo visudo

然后找到 %sudo ALL=(ALL:ALL) ALL 这一行修改为 %sudo ALL=(ALL:ALL) NOPASSWD:ALL有安全风险,慎用。

2. 修改软件源

Ubuntu 默认的软件源是境外的,速度上会有些问题,我们可以在 Software & Updates (软件和更新) 中选择国内的镜像。

3. 更新系统

# 更新本地包数据库
sudo apt update
# 更新所有已安装的包(也可以使用 full-upgrade)
sudo apt upgrade
# 自动移除不需要的包
sudo apt autoremove

常用的清理命令如下:

命令 描述
apt autoclean 将已删除软件包的 .deb 安装文件从硬盘中删除
apt clean 同上,但会把已安装的软件包的安装包也删除掉
apt autoremove 删除为了满足其他软件包的依赖而安装,但现在不再需要的软件包
apt remove [软件包名] 删除已安装的软件包(保留配置文件)
apt --purge remove [软件包名] 删除已安装包(不保留配置文件)

4. 高分屏适配

默认情况下,高分屏下 UI 元素显得过小,因此需要调整界面的缩放比例。可以通过如下命令设置:

gsettings set org.gnome.desktop.interface scaling-factor 2

对于非整数倍的缩放,需要根据图形接口协议(Wayland/X11)来进行调整。具体命令如下:

echo $XDG_SESSION_TYPE

对于 Wayland:

gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"

对于 X11:

xrandr --output DP-4 --scale 1.25x1.25

确保 output 参数正确,可以通过 xrandr 命令查看。

5. 安装 Python2

Ubuntu 20.04 默认安装了 Python3,但某些工具或脚本可能仍需要 Python2:

sudo apt install python2

6. 安装 Git

sudo apt install git

7. 中文输入法

由于搜狗输入法目前不支持 Ubuntu 20.04,推荐使用 ibus-libpinyin

sudo apt install ibus-libpinyin ibus-clutter

Language Support 中更改 Keyboard input method systemIBUS,然后在 Region & Language 中新增 Chinese (Intelligent Pinyin)


二. 打造你的命令行工具

1. 安装 Terminator

Terminator 是一个强大的 Terminal 工具,支持分屏等功能:

sudo add-apt-repository ppa:gnome-terminator
sudo apt update
sudo apt install terminator

2. 配置 Shell(安装 zsh 和 oh-my-zsh)

Zsh 比 bash 更加强大,推荐安装并设置为默认 shell:

sudo apt install zsh
sudo chsh -s /bin/zsh

安装 oh-my-zsh 来简化配置:

wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

3. ZSH 配置

主要集中在 ~/.zshrc 文件中,可以添加常用命令的别名和选择主题,例如:

alias cls='clear'
alias ll='ls -l'

设置主题:

ZSH_THEME="robbyrussell"

4. ZSH 插件安装

推荐的插件有 autojump, zsh-autosuggestions, zsh-syntax-highlighting

sudo apt install autojump
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

~/.zshrc 中配置:

plugins=(autojump zsh-autosuggestions zsh-syntax-highlighting)

5. 有趣的命令行小玩具

安装一些有趣的小工具:

# 终端黑客帝国屏保
sudo apt install cmatrix
cmatrix

# 终端小火车动效
sudo apt install sl
sl

# 显示系统信息及 ASCII 化的 Linux 发行版图标
sudo apt install screenfetch
screenfetch

三. 软件安装

1. 安装 Typora

Typora 是一款开源的 Markdown 编辑器:

wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
sudo add-apt-repository 'deb https://typora.io/linux ./'
sudo apt update
sudo apt install typora

2. JetBrains 全家桶

安装 JetBrains 的 ToolBox App 后可以无脑一键安装旗下各种 IDE,包括 Android Studio。

3. 其它应用程序安装

对于提供 .deb 安装包的应用,可以执行以下命令:

sudo apt install ./<file>.deb

对于需要缩放的应用,可以使用如下命令启动:

QT_SCALE_FACTOR=2 zoom
QT_SCALE_FACTOR=2 netease-cloud-music

4. 使用 Deepin-Wine 安装 QQ/TIM/微信/Office 等

Deepin-Wine 是深度社区开发的 Wine 版本,支持多种 Windows 应用:

git clone git@github.com:wszqkzqk/deepin-wine-ubuntu.git
cd deepin-wine-ubuntu
sudo chmod +x install_2.8.22.sh
./install_2.8.22.sh

下载并安装 deep-wine-ubuntu 提供的 .deb 软件包。

5. 安装 rpm 格式的软件

使用 Alien 将 .rpm 转换为 .deb 安装包:

sudo add-apt-repository universe
sudo apt update
sudo apt install alien
sudo alien XMind-2020.rpm
sudo dpkg -i XMind-2020.deb

四. 桌面美化

1. 安装 tweek

sudo apt install gnome-tweak-tool

2. 安装插件扩展支持

sudo apt install gnome-shell-extensions chrome-gnome-shell

3. 常用插件清单

可在 GNOME Extensions 网站上探索更多插件。

4. 主题

可在 GNOME-LOOK 上下载各种桌面主题、Shell 主题、图标(icon)主题。

5. 壁纸

推荐几个下载 4K 8K 超高清壁纸的网站:


五. 使用问题记录

问题一:Windows、Ubuntu 双系统时间不统一

解决方案:禁用 Ubuntu 中的 UTC:

timedatectl set-local-rtc 1 --adjust-system-clock

问题二:Ubuntu 循环登陆

解决方案:使用 LightDM 替换 gdm3:

sudo apt-get install lightdm
sudo reboot

问题三:NVIDIA 驱动修复

解决方案:手动安装显卡驱动:

sudo apt install build-essential libglvnd-dev pkg-config
sudo telinit 3
sudo apt purge "nvidia*"
sudo bash NVIDIA-Linux-x86_64-440.82.run
sudo reboot

参考文档

  • HiDPI#非整数倍缩放
  • 终极 Shell
  • How to install the NVIDIA drivers on Ubuntu 20.04 Focal Fossa Linux

本文由作者 王大神 原创发布于 大神网的AI博客。

转载请注明作者:王大神

原文出处:如何优化 Ubuntu 20.04 LTS 的性能和功能?

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 2024年5月29日
下一篇 2024年5月29日