3

The default zsh version located at /bin/zsh is 5.7.1 (x86_64-apple-darwin19.0).

I brew installed a new version, added /usr/local/bin/zsh to /etc/shells, and issued chsh -s /usr/local/bin/zsh to change it to that one - it's output: chsh: no changes made. I've also tried issuing sudo dscl . -create /Users/$USER UserShell /usr/local/bin/zsh and still see, upon restarting the command line and the machine itself, which zsh and type zsh showing /bin/zsh.

I checked System Preferences -> unlock -> right click my user and click Advanced Options -> and I see /usr/local/bin/zsh for Login shell.

On command line:

  • which zsh outputs /bin/zsh
  • echo $0 outputs -zsh
  • ps -o comm= $$ outputs -zsh
  • echo $SHELL outputs /usr/local/bin/zsh
  • type zsh outputs zsh is /bin/zsh
  • /usr/local/bin/zsh --version outputs zsh 5.8 (x86_64-apple-darwin19.3.0)
  • zsh --version outputs zsh 5.7.1 (x86_64-apple-darwin19.0)

I'm wondering, how can I ensure version 5.8 is being used?

Could it be that because /bin is before /usr/local/bin in my PATH, that /bin/zsh is resolved instead of /usr/local/bin/zsh, assuming shell binary is also resolved using PATH?

2
  • 2
    "Could it be that because /bin is before /usr/local/bin in my PATH, that /bin/zsh is resolved instead of /usr/local/bin/zsh, assuming shell binary is also resolved using PATH?" - Yes, just tested in a Catalina VM
    – klanomath
    Apr 26, 2020 at 18:48
  • Great, thanks for quick confirmation. I'm afraid of switching the order on the PATH because of version issues that may arise. I could try and see what breaks. I'm wondering if there's another way to only get /usr/local/bin/zsh resolved while leaving /bin before /usr/local/bin. I wonder if that's to explicitly add that binary on the path. I see a similar issue with vi - vi.stackexchange.com/questions/11058/…. Homebrew has a custom flag for this situation.
    – foamroll
    Apr 26, 2020 at 19:18

1 Answer 1

1

The PATH evaluation command in /etc/zprofile probably overrides your shell settings in the Directory Services.

If you give priority to /bin in the global PATH (or even in the user's .zprofile/.zshrc/...) Apple's zsh will be your default shell exec despite other settings in your user ds profile.


If you want to keep your current PATH settings (prioritize /bin) you can move/copy brew's zsh link to a (new) dir like /usr/local/zsh/bin/.

Then change the shell dir and the shell with sudo nano /etc/shells and chsh -s /usr/local/zsh/bin/zsh and finally change your PATH in .zprofile/.zshrc to

export PATH="/usr/local/zsh/bin:$PATH"

You have to renew the zsh link in /usr/local/zsh/bin/ after updating/upgrading brew's zsh!

4
  • I'm questioning this - "You have to renew the zsh link in /usr/local/zsh/bin/ after updating/upgrading brew's zsh!" because when I do ls -la in /usr/local/zsh/bin I see: zsh -> /usr/local/bin/zsh, which itself is a link to ../Cellar/zsh/5.8/bin/zsh-5.8. So, I'm thinking that upgrading with brew, I wouldn't have to update the second link.
    – foamroll
    Apr 26, 2020 at 20:29
  • @sugarcane After an update/upgrade of zsh the link still contains the path to ../Cellar/zsh/5.8/bin/zsh-5.8 while the real path will be e.g. ../Cellar/zsh/5.8.1/bin/zsh-5.8.1.
    – klanomath
    Apr 26, 2020 at 20:31
  • Yes, I see it - when I do this (full path): readlink /usr/local/bin/zsh, I get: ../Cellar/zsh/5.8/bin/zsh. Questioning this all, as I may forget to update the 2nd link upon brew update, unless I do scheduling or scripting to keep it up to date, as macOS updates may update this, or alternatively I could move up /usr/local/bin in path, as brew suggests. There's a security issue with that suggestion, albeit one that's considered "bikeshedding": discourse.brew.sh/t/….
    – foamroll
    Apr 26, 2020 at 20:53
  • @sugarcane I don't really advocate my solution (and implemented it in my VM only to test the whole scenario) but the OP explicitly requested it: " I'm afraid of switching the order on the PATH because of version issues that may arise. I could try and see what breaks. I'm wondering if there's another way to only get /usr/local/bin/zsh resolved while leaving /bin before /usr/local/bin. I wonder if that's to explicitly add that binary on the path. I see a similar issue with vi..." (see the OP's comment in the question.
    – klanomath
    Apr 26, 2020 at 21:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .