As a web developer these days, we typically need to be able to switch versions of Node on the fly, for this we want to install Node Version Manager on a clean install of our machine, we don't want to start by installin Node on it's own as this will give us a single version of Node (whichever we decide to install)
If you install Node first and then try to install NVM, things can get complicated, so if you have already installed Node, my suggestion is to completely remove it before installing NVM.
As well, NVM is explicitly not supported when installed via homebrew - the only correct way to install it is with the install script in NVM's Readme.
So if you have a brand new Mac M1 these are the steps you need to go through.
- Navigate to your home directory
cd ~
- Create a .zshrc file
touch .zshrc
- Install NVM using the curl command found on the NVM Readme
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
This last command will update your .zshrc
file to look like the following:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
- Install Node using NVM
nvm install node
This will install the latest version of Node, in my case it setup Node v 17.x, to setup alternate version we can specify by version or --lts
NOTE: Node version before v 15.x are not necessarily ARM compatible, but it seems that Node has addressed this issue, so if you do install a version prior to v 15.x You should not need to use Rosetta to run.
- Install LTS version of Node
nvm install --lts
Running this command installed the current LTS at the time of this GIST which is v 16.x, I think I will try to stick with this version or better when developing, however; that's the beauty of NVM is that if I need and older version it's easy to switch!
- List the versions of Node I have installed
nvm ls
- Select an alternate version that I have installed
nvm use 16
or
nvm use --lts
Those will both allow me to use the LTS version we just installed! Hope that helps, Happy Noding~!