1. 安装必要依赖
# 更新系统 sudo apt update && sudo apt upgrade -y # 安装 zsh 和 git(如果尚未安装) sudo apt install zsh git curl wget fonts-powerline -y2. 安装 Oh My Zsh
# 1.使用 curl sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # 2.使用 wget sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # 3.国内镜像(如果 GitHub 访问慢) # 使用 gitee 镜像 sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)" # 或手动下载安装 git clone https://gitee.com/mirrors/oh-my-zsh.git ~/.oh-my-zsh cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc3.设置 zsh 为默认 shell
# 查看当前 shell echo $SHELL # 切换为 zsh(如果安装脚本没自动切换) chsh -s $(which zsh) # 验证是否切换成功 echo $SHELL # 应该显示 /usr/bin/zsh # 注销并重新登录,或重启终端使更改生效。4. 配置 Oh My Zsh
# 修改主题(推荐主题) 编辑 ~/.zshrc: vim ~/.zshrc # 找到 ZSH_THEME 行,修改为: # 推荐的主题: ZSH_THEME="agnoster" # 需要安装 powerline 字体 ZSH_THEME="robbyrussell" # 默认主题 ZSH_THEME="af-magic" # 简洁美观 ZSH_THEME="bira" # 信息丰富 ZSH_THEME="ys" # 经典简洁 # 安装 Powerline 字体(用于特殊符号) # 下载并安装字体 sudo apt install fonts-powerline -y # 或者手动安装 Meslo 字体(推荐给 agnoster 主题) sudo apt install fonts-meslo -y 配置终端使用 Powerline 字体: 打开终端 菜单 → 首选项 → 文本 → 自定义字体 选择 "Meslo LG S" 或 "Ubuntu Mono derivative Powerline" # 启用插件 # 安装常用插件 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting 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-completions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-completions # 编辑 ~/.zshrc 启用插件 nano ~/.zshrc 修改插件列表: plugins=( git zsh-syntax-highlighting zsh-autosuggestions zsh-completions sudo extract docker ) # 应用配置 # 重新加载配置 source ~/.zshrc # 或重新打开终端6. 安装额外的主题(可选)
# Powerlevel10k(强大的主题) git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k # 然后在 ~/.zshrc 中设置 ZSH_THEME="powerlevel10k/powerlevel10k"