Linux下安装zsh

警告
本文最后更新于 2022-10-11,文中内容可能已过时,请谨慎使用。

以官方文档为准

安装 oh-my-zsh 前的准备:

  • A Unix-like operating system: macOS, Linux, BSD. On Windows: WSL2 is preferred, but cygwin or msys also mostly work.
  • Zsh should be installed (v4.3.9 or more recent is fine but we prefer 5.0.8 and newer). If not pre-installed (run zsh --version to confirm), check the following wiki instructions here: Installing ZSH
  • curl or wget should be installed
  • git should be installed (recommended v2.4.11 or higher)

其他系统自行查看:Installing ZSH

sudo apt install zsh

github 地址:https://github.com/ohmyzsh/ohmyzsh

sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
/images/img/20220215211324.png
安装成功

使用vim打开.zshrc配置文件

vim ~/.zshrc

修改主题为ZSH_THEME="ys"

/images/img/20220215211921.png
修改主题

退出zsh重新进入zsh即可生效

~/.oh-my-zsh/plugins中可以看到所有自带的插件,将插件名称添加到.zshrcplugin字段中.

例如:

plugins=(
  git
  bundler
  dotenv
  macos
  rake
  rbenv
  ruby
)

以安装zsh-autosuggestions举例,插件地址在:https://github.com/zsh-users/zsh-autosuggestions

将该项目直接克隆到plugins文件夹下

cd ~/.oh-my-zsh/plugins
git clone git@github.com:zsh-users/zsh-autosuggestions.git

最后将插件名称添加到.zshrcplugin字段中.

plugins=(
	zsh-autosuggestions
)

退出zsh重新进入zsh即可生效

chsh -s $(which zsh)
exec zsh

重启生效

sudo ln -s $HOME/.oh-my-zsh /root/.oh-my-zsh
sudo ln -s $HOME/.zshrc /root/.zshrc

如果想两个用户配置不同步改变,可以使用下列命令

sudo cp -r /home/你的用户名/.oh-my-zsh /root
sudo cp -r /home/你的用户名/.zshrc /root
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/uninstall.sh)"

相关文章