Install Nodejs the right way in M1 & M2 Mac.
This guide is specifically for MacBook models M1 and M2 for a new and fresh install.
Step 1 - Install Homebrew
Link: https://brew.sh/
Brew give you another steps (like that) and do every command every steps.
- Add Homebrew to your PATH in ~/.zprofile:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Last, brew doctor
tell you everything if install perfect or there is any issue.
Step 2 - Install Node version Manager aka NVM
You should create NVM's working directory if it doesn't exist:
Add the following to ~/.zshrc
or your desired shell configuration file:
Last, do source ~/.zshrc
or restart terminal.
Step 3 - Install Nodejs
Open website nodejs website nodejs.org to check which version you need to install LTS version or Stable. You can change later with NVM manager.
Step 3 - Install NPM
Open website nodejs website nodejs.org to check which version you need to install LTS version or Stable. You can change later with NVM manager.
Tips
Here is other commends which help
#Some packages are not functioning properly on Macs with M1 or M2 processors.
npm install node-gyp
#switch node version
nvm use (node version 20 or 21)
Reference link:
https://www.youtube.com/watch?v=5jmtF6qpWq8