【先安裝zsh,再安裝Oh-My-Zsh】
1. 安裝zsh
- 安裝ZSH命令:
- Redhat/Centosyum install zsh
- Debian/Ubuntuapt-get install zsh
- 設置zsh爲默認
shell chsh -s $(which zsh)
2. 利用Oh-My-Zsh配置zsh
可以使用curl或wget下載Oh-My-Zsh的安裝文件:
- 使用curl安裝
- 命令:
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)”
- 命令:
- 使用wget安裝
- 命令:
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)”
- 命令:
使用上述命令,可能比較慢,可以採用手動下載的方式進行下載,即直接打開 https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.s將腳本存到服務器,後面使用sh install.sh
命令運行安裝。
3. 可能會遇到的問題
上述方法在ubuntu、Mac中使用沒有問題,非常順暢,但在centos中遇到了下面這些問題,記錄一下。
環境相關信息:
OS版本:CentOS Linux release 7.6.1810 (Core)
kernel版本:3.10.0-957.el7.x86_64
3.1. colors: function definition file not found
該錯誤類似下面這種情況
/home/marcel/.oh-my-zsh/lib/theme-and-appearance.zsh:2: colors: function definition file not found
/home/marcel/.oh-my-zsh/oh-my-zsh.sh:78: compinit: function definition file not found
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:80: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:93: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:100: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:109: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:119: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:129: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:138: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:144: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:147: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:150: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:153: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:163: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:166: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:168: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:182: command not found: compdef
/home/marcel/.oh-my-zsh/plugins/git/git.plugin.zsh:193: command not found: compdef
$SPACESHIP_PROMPT_TRUNC is deprecated. Use $SPACESHIP_DIR_TRUNC instead.
spaceship_setup:3: add-zsh-hook: function definition file not found
spaceship_setup:4: add-zsh-hook: function definition file not found
$SPACESHIP_PROMPT_TRUNC is deprecated. Use $SPACESHIP_DIR_TRUNC instead.
spaceship_setup:3: add-zsh-hook: function definition file not found
spaceship_setup:4: add-zsh-hook: function definition file not found
嘗試網上給出的方法:
- rm ~/.zcompdump* ,在~路徑下沒有發現.zcompdump文件
- 重裝 oh-my-zsh
經過上面的嘗試都不生效,後來找到了另一個方法,添加$FPATH
到 ~/.zshrc配置文件中即可解決該問題。具體爲, 在**~/.zshrc**配置文件添加如下語句:
export FPATH=/usr/share/zsh/5.0.2/functions/:$FPATH
上述的/usr/share/zsh/5.0.2/
中的5.0.2是zsh版本,可以通過zsh --version
或 $SHELL --version
命令查看zsh版本信息。
設置完成後,通過source ~/.zshrc
命令即可生效。但自己在執行source ~/.zshrc
命令時有發生了下面的錯誤。
3.2 syntax error near unexpected token `(’
經過3.1 的修改後,執行source ~/.zshrc
命令時有發生了下面的錯誤:
--> source ~/.zshrc
-bash: autoload: command not found
-bash: /Users/suy/.oh-my-zsh/oh-my-zsh.sh: line 41: syntax error near unexpected token `('
-bash: /Users/suy/.oh-my-zsh/oh-my-zsh.sh: line 41: `for plugin($plugins); do'
可以通過依次執行下面的命令解決該問題:
zsh
chsh -s $(which zsh)
參考【github】
執行上述chsh -s $(which zsh)
命令可能會有 chsh says “invalid shell”
類似的提示,解決方法見3.3
3.3 chsh says “invalid shell”
執行chsh -s $(which zsh)
命令可能會有 chsh says “invalid shell”
類似的提示,解決方法:
Add zsh to /etc/shells:
command -v zsh | sudo tee -a /etc/shells
You can now use chsh to set zsh as shell:
sudo chsh -s "$(command -v zsh)" "${USER}"
參考【stackexchange】
3.4 升級ih-my-zsh
通過在終端中即將入如下命令即可:
upgrade_oh_my_zsh
可參考 【stackoverflow - issue】