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
orwget
should be installedgit
should be installed (recommended v2.4.11 or higher)
1.Ubuntu 安装 zsh
其他系统自行查看:Installing ZSH
sudo apt install zsh
2.安装 oh-my-zsh
github 地址:https://github.com/ohmyzsh/ohmyzsh
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
3.修改主题
使用vim
打开.zshrc
配置文件
vim ~/.zshrc
修改主题为ZSH_THEME="ys"
退出zsh
,重新进入zsh
即可生效
4.安装插件
在~/.oh-my-zsh/plugins
中可以看到所有自带的插件,将插件名称添加到.zshrc
中plugin
字段中.
例如:
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
最后将插件名称添加到.zshrc
中plugin
字段中.
plugins=(
zsh-autosuggestions
)
退出zsh
,重新进入zsh
即可生效
5.修改默认终端为 zsh
chsh -s $(which zsh)
exec zsh
重启生效
6.root 用户使用同样的 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
6.卸载 oh-my-zsh
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/uninstall.sh)"