centos下安装、配置zsh & 相关问题解决

【先安装zsh,再安装Oh-My-Zsh】

1. 安装zsh

  • 安装ZSH命令:
    - Redhat/Centos yum install zsh
    - Debian/Ubuntu apt-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

尝试网上给出的方法:

  1. rm ~/.zcompdump* ,在~路径下没有发现.zcompdump文件
  2. 重装 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

发布了134 篇原创文章 · 获赞 30 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/donaldsy/article/details/103517812
今日推荐