CentOS7 源码安装 zsh 及 配置 Oh my zsh

因为一些国内不能访问 github,所以本教程使用的 gitee 下载源文件。

环境

Centos7 最小化安装环境

源码编译安装

如果需要安装 powerlevel10k 则需要源码安装最新版本,yum 源中的 5.0.2 版本是不支持的

1
2
3
4
5
6
7
8
9
10
11
12
13
yum -y install wget git gcc ncurses-devel
wget http://ftp.funet.fi/pub/unix/shells/zsh/zsh-5.8.tar.xz /opt/software
tar -xvf zsh-5.8.tar.xz

cd zsh-5.8
./configure
make && make install

# 将zsh加入/etc/shells
vim /etc/shells
# 添加:
/usr/local/bin/zsh

更改默认终端

1
chsh -s /usr/local/bin/zsh

这时候打开终端软件,应该就会默认进入 zsh 了。

如果 shell 连接进入 bash 则需要重启一下系统

配置 oh-my-zsh

  1. 从 gitee 拉取 oh-my-zsh

    国内镜像源 (每日更新一次)

1
git clone https://gitee.com/mirrors/oh-my-zsh.git ~/.oh-my-zsh
  1. 默认配置
    1
    cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

安装插件

zsh-syntax-highlighting 命令高亮插件

1
git clone https://gitee.com/dawnwords/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

zsh-autosuggestions 自动建议补全

1
git clone https://gitee.com/lhaisu/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

安装 autojump 目录跳转

1
2
3
git clone https://gitee.com/gentlecp/autojump.git
cd autojump
./install.py

执行成功后将出现的代码复制到 .zshrc 末尾处,可能有少许差异,不生效则需要以下面模版进行修改。

1
2
vim ~/.zshrc
[[ -s /root/.autojump/etc/profile.d/autojump.sh ]] && . /root/.autojump/etc/profile.d/autojump.sh

插件配置

同样是打开.zshrc 文件,找到 plugins=(git),在这里增加自己想要的插件即可,多个插件名称之间使用空格或者换行分开(不能使用逗号)。
vim ~/.zshrc

1
2
3
4
5
6
7
plugins=(
git
sudo
zsh-autosuggestions
zsh-syntax-highlighting
autojump
)

每次修改完 .zshrc 都需要

1
source ~/.zshrc