Administrator
发布于 2021-08-08 / 3319 阅读 / 0 评论 / 0 点赞

Centos7-Linux安装zsh和oh-my-zsh(内含国内安装方法)

Centos7-Linux安装zsh和oh-my-zsh(内含国内安装方法)

一、安装zsh

yum install -y zsh
  • 出现如下信息说明安装成功

image-20210808162517367

  • 设置zsh为默认的shell
chsh -s /bin/zsh

确保在root权限下切换

image-20210808162756887

二、安装git

一般情况下,如果是买的服务器,默认是会有git的,但是自己装虚拟机还是需要装一下git的

yum install -y git

三、安装oh-my-zsh

  • 官方推荐安装方式
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

上面的方法尽管一步到位,但是在国内,我用上面的方法一直出现clone不下来的情况。

  • 如果出现一直clone不下来,就采用下面的方法

  • 先把install.sh文件下载下来(这是gitee的国内镜像源)

wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
  • 然后给install.sh添加权限
chmod +x install.sh
  • 用vim打开install.sh发现,有的地方还是有clone github的代码,所以做如下修改
vi install.sh
  • 找到以下部分
# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
  • 把中间两行修改为:
REPO=${REPO:-mirrors/oh-my-zsh}
REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}
  • 然后 :wq!保存

  • 然后执行install.sh

sh install.sh
  • 出现如下说明安装成功

image-20210808164552418

四、oh-my-zsh常用插件

zsh-syntax-highlighting :提供了语法高亮显示。

zsh-autosuggestions :它会根据历史记录和完成情况建议您键入的命令,而且快速/不干扰自动提示。

zsh-completions :命令自动补全。

安装:

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
  • 你可能会发现,又clone不下来,那就复制仓库名字,取gitee中搜索,替换链接即可
git clone https://gitee.com/mo2/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

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

git clone https://gitee.com/wangnd/zsh-completions.git ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
  • 下载好了以后,修改配置(.zshrc)

1、取消第二行的注释

export PATH=$HOME/bin:/usr/local/bin:$PATH

2、设置插件

修改 plugins=(git)改成:

plugins=(git zsh-completions zsh-autosuggestions zsh-syntax-highlighting)
autoload -U compinit && compinit

End.

给个一键三连吧~


评论