在 MacOS 中使 ZSH 默认 Shell
Making ZSH default Shell in MacOSX
我在 Mac 上安装了 zsh。现在我想将其设为默认 shell 而不是 Bash。但是我好像运行陷入了以下错误:
$ echo $SHELL
/bin/bash
$ chsh -s /usr/bin/zsh
Changing shell for harshamv.
Password for harshamv:
chsh: /usr/bin/zsh: non-standard shell
三个简单的步骤:
which zsh
这为您提供了通往 zsh 的路径
- 然后
chsh -s /bin/zsh
或者如果不同则替换你的 zsh 路径
- 重启你的机器
在我的工作 MacBook 上,我必须这样做:
sudo chsh -s /usr/local/bin/zsh my_user_name
然后我必须创建一个 .bash_profile
文件,使我的终端每次打开时都切换到 z-shell:
touch ~/.bash_profile
echo 'export SHELL=$(which zsh)' >> ~/.bash_profile
echo 'exec $(which zsh) -l' >> ~/.bash_profile
最后一个思路是借用的from here。
我可以通过执行以下操作来实现此功能:
- 转到系统偏好设置
- 点击"Users & Groups"
- 单击锁形图标进行更改。
- 右击当前用户->高级选项
- 在下拉列表中将登录名 shell 更改为 /bin/zsh。
- 打开一个新终端并用
echo $SHELL
验证
正确答案应该已经解决了您的问题:
chsh: /usr/bin/zsh: non-standard shell
出现这种情况的原因是因为 chsh
将只接受文件 /etc/shells 中定义的 shell,正如您阅读 [= 的手册所见12=]:
chsh will accept the full pathname of any executable file on
the system. However, it will issue a warning if the shell is not
listed in the
/etc/shells file.
要解决此问题并使 zsh 成为默认 shell,您应该这样:
$ sudo echo "$(which zsh)" >> /etc/shells
$ chsh -s $(which zsh)
显然,我假设 zsh
在您的路径中。例如,如果您选择安装带有 brew install zsh
.
的最新 zsh
,此解决方案也适用
编辑(感谢 ThisIsFlorianK 的评论):
根据您的 shell 设置,您可能会收到一条消息 /etc/shells: Permission denied
。您可以找到有关此问题的信息 here.
要解决此问题,请改用以下内容:
$ sudo sh -c "echo $(which zsh) >> /etc/shells"
$ chsh -s $(which zsh)
我在 Mac 上安装了 zsh。现在我想将其设为默认 shell 而不是 Bash。但是我好像运行陷入了以下错误:
$ echo $SHELL
/bin/bash
$ chsh -s /usr/bin/zsh
Changing shell for harshamv.
Password for harshamv:
chsh: /usr/bin/zsh: non-standard shell
三个简单的步骤:
which zsh
这为您提供了通往 zsh 的路径
- 然后
chsh -s /bin/zsh
或者如果不同则替换你的 zsh 路径 - 重启你的机器
在我的工作 MacBook 上,我必须这样做:
sudo chsh -s /usr/local/bin/zsh my_user_name
然后我必须创建一个 .bash_profile
文件,使我的终端每次打开时都切换到 z-shell:
touch ~/.bash_profile
echo 'export SHELL=$(which zsh)' >> ~/.bash_profile
echo 'exec $(which zsh) -l' >> ~/.bash_profile
最后一个思路是借用的from here。
我可以通过执行以下操作来实现此功能:
- 转到系统偏好设置
- 点击"Users & Groups"
- 单击锁形图标进行更改。
- 右击当前用户->高级选项
- 在下拉列表中将登录名 shell 更改为 /bin/zsh。
- 打开一个新终端并用
echo $SHELL
验证
正确答案应该已经解决了您的问题:
chsh: /usr/bin/zsh: non-standard shell
出现这种情况的原因是因为 chsh
将只接受文件 /etc/shells 中定义的 shell,正如您阅读 [= 的手册所见12=]:
chsh will accept the full pathname of any executable file on the system. However, it will issue a warning if the shell is not listed in the /etc/shells file.
要解决此问题并使 zsh 成为默认 shell,您应该这样:
$ sudo echo "$(which zsh)" >> /etc/shells
$ chsh -s $(which zsh)
显然,我假设 zsh
在您的路径中。例如,如果您选择安装带有 brew install zsh
.
zsh
,此解决方案也适用
编辑(感谢 ThisIsFlorianK 的评论):
根据您的 shell 设置,您可能会收到一条消息 /etc/shells: Permission denied
。您可以找到有关此问题的信息 here.
要解决此问题,请改用以下内容:
$ sudo sh -c "echo $(which zsh) >> /etc/shells"
$ chsh -s $(which zsh)