lewagon/dotfiles

Update zprofile to find brew, gh, code, pyenv, direnv ... on Apple silicon

Closed this issue · 1 comments

On Apple silicon macs, during or after setup, students encounter one of the following:

  • a command not found error when executing commands like brew, gh, code
  • no virtualenv shown in terminal (due to pyenv not working)
  • wrong python version (due to pyenv not working)
  • command not found: direnv when starting the terminal

Root cause:

  • On Apple silicon macs, brew is installed in a different location than on Intel macs (/opt/homebrew).
  • When installing brew a line is added to .zprofile to add some environment variables to add this new location to PATH: eval "$(/opt/homebrew/bin/brew shellenv)"
  • But then we execute our dotfiles/install.sh which overwrites the old .zprofile.
  • First time student logs out and logs in again the commands are no longer found.

Solution:
Add the following first lines to our zprofile:

# Required to find brew on Mac with Apple silicon
eval "$(/opt/homebrew/bin/brew shellenv 2> /dev/null)"

Compatibility of the proposed solution with Intel macs or Linux or WSL systems:
The eval command will not execute but will generate an error (command not found). The proposed line simply redirects the stderr output to suppress the warning.
The script continues execution afterwards.

Thanks 🙏 , just added the line 👌