在 macOS 上安裝 ZSH 作為預設 shell

最簡單的方法是使用 brew

brew install zsh

安裝後,你可能希望通過執行以下操作將其設定為預設 shell:

sudo echo '/usr/local/bin/zsh' >> /etc/shells
chsh -s /usr/local/bin/zsh

如果你安裝了 git,並且安裝了所需的命令列工具,則可以編譯並安裝最新版本(截至此編輯時為 5.2),如下所示:

# clone the source
git clone git://git.code.sf.net/p/zsh/code zsh

# checkout the required version, say, zsh-5.2
cd zsh && git checkout zsh-5.2

# check the documentation for help on configuration options
./Util/preconfig
./configure --prefix=/usr/local \
  --enable-fndir=/usr/local/share/zsh/functions \
  --enable-scriptdir=/usr/local/share/zsh/scripts \
  --enable-site-fndir=/usr/local/share/zsh/site-functions \
  --enable-site-scriptdir=/usr/local/share/zsh/site-scripts \
  --enable-runhelpdir=/usr/local/share/zsh/help \
  --enable-etcdir=/etc \
  --mandir=/usr/local/share/man \
  --infodir=/usr/local/share/info \
  --enable-cap \
  --enable-maildir-support \
  --enable-multibyte \
  --enable-pcre \
  --enable-zsh-secure-free \
  --with-tcsetpgrp

# compile and check if compiled successfully
make -j5 && make check
# you should see results of successful test scripts

sudo make install

同樣,你可以通過將 zsh 新增到/etc/shells 並使用如上所述的 chsh 將其作為預設 shell。