To install packages like NPM on MacOS, Homebrew is a well working tool. However I faced some issues on my M2 MacBook Air from 2022. This is how I solved it.
First install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Usually, it should be possible to run brew commands now, but this error may appear:
zsh: command not found: brew
If Homebrew was installed successful, the next solution may be, to add two lines to the bottom of the zshrc file:
cd /etc cp zshrc zshrc_backup // create a backup file, if you mess up the original one sudo nano zshrc
Add these two lines at the bottom of the file:
export PATH=/opt/homebrew/bin:$PATH export PATH=/opt/homebrew/sbin:$PATH
Hit ctrl + o and then enter to save. Then Hit ctrl + x to exit the editor. A system restart may be necessary!
Please check the provided sources for more information. Links below.