bash 在 MacOSX 中使 ZSH 成为默认 Shell
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31034870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making ZSH default Shell in MacOSX
提问by Harsha M V
I installed zsh on my Mac. and now i want to make it the default shell instead of Bash. But I seem to be running into the following error:
我在 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
采纳答案by Quentin Perez
3 easy steps:
3个简单的步骤:
which zsh
this gives you your path to zsh- Then
chsh -s /bin/zsh
or replace path to your zsh if different - Restart your machine
which zsh
这为您提供了 zsh 的路径- 然后
chsh -s /bin/zsh
或替换您的 zsh 的路径(如果不同) - 重启你的机器
回答by dangom
The correct answer should've addressed your problem:
正确答案应该已经解决了您的问题:
chsh: /usr/bin/zsh: non-standard shell
chsh: /usr/bin/zsh: 非标准外壳
The reason this is the case is because chsh
will only accept shells that are defined in the file /etc/shells, as you can see by reading the manual for chsh
:
之所以出现这种情况,是因为chsh
它只接受在文件 /etc/shells 中定义的 shell,正如您通过阅读以下手册可以看到的chsh
:
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.
chsh 将接受系统上任何可执行文件的完整路径名。但是,如果 shell 未在 /etc/shells 文件中列出,它将发出警告。
To solve this problem and make zsh the default shell, you should thus:
要解决此问题并使 zsh 成为默认 shell,您应该:
$ sudo echo "$(which zsh)" >> /etc/shells
$ chsh -s $(which zsh)
Obviously, I assume that zsh
is in your path here. This solution will also work if you, for example, choose to install the latest zsh
with brew install zsh
.
显然,我认为这zsh
在您的路径中。例如,如果您选择zsh
使用brew install zsh
.
EDIT(thanks for ThisIsFlorianK for the comment):
编辑(感谢 ThisIsFlorianK 的评论):
Depending on your shell setup you may get a message saying /etc/shells: Permission denied
. You can find information about this issue here.To work around it, use the following instead:
根据您的 shell 设置,您可能会收到一条消息说/etc/shells: Permission denied
. 您可以在此处找到有关此问题的信息。要解决此问题,请改用以下内容:
$ sudo sh -c "echo $(which zsh) >> /etc/shells"
$ chsh -s $(which zsh)
回答by Nate Jenson
I was able to get this working by doing the following:
通过执行以下操作,我能够使其正常工作:
- Go to System Preferences
- Click on "Users & Groups"
- Click the lock to make changes.
- Right click the current user -> Advanced options
- Change the login shell to /bin/zsh in the dropdown.
- Open a new terminal and verify with
echo $SHELL
- 进入系统偏好设置
- 点击“用户和组”
- 单击锁以进行更改。
- 右键单击当前用户 -> 高级选项
- 在下拉列表中将登录 shell 更改为 /bin/zsh。
- 打开一个新终端并验证
echo $SHELL
回答by sakovias
On my work MacBook I had to do this:
在我的工作 MacBook 上,我必须这样做:
sudo chsh -s /usr/local/bin/zsh my_user_name
Then I had to create a .bash_profile
file to make my terminal switch to z-shell every time I open it:
然后我必须创建一个.bash_profile
文件,使我的终端每次打开时都切换到 z-shell:
touch ~/.bash_profile
echo 'export SHELL=$(which zsh)' >> ~/.bash_profile
echo 'exec $(which zsh) -l' >> ~/.bash_profile
The last idea was borrowed from here.
最后一个想法是从这里借来的。