How to Install nvm for Mac & Windows
nvm is a command line utility that will install and manage multiple versions of Node.js with easy switching between.
The Node.js version installed on your computer will be out of date by the time you take off the shrink wrap. You’ll need to install a newer version of Node.js.
nvm will install it for you AND allow you two switch between versions as needed.
Let’s say you’re working on two projects. One is a Next.js app running on Node 18. Another is a side project and you’ve decided to jump to Node 20. How annoying would it be to uninstall Node and reinstall node every time you switched between these projects.
With nvm, you can toggle between these by running
nvm use 20 to use Node v20, then run
nvm use 18 to switch back.
What Does nvm Stand For?
Node Version Manager.
If you’re texting it means never mind, but nevermind that.
How to Install nvm
You can install it on Mac and Unix by opening a the Terminal app and running the following command in any directory.
If you’ve never used a command line before they can daunting! It’s like you’re speaking straight to your computer rather than talking through an interpreter.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bashCode language: Bash (bash)
You really shouldn’t copy this code and run it. This will run arbitrary code on your computer. You can check the URl and see this is in the nvm-sh organization, but still – just a recommendation. You can head to the official repository and copy the terminal command from there.
You can install it for Ubuntu by running:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bashCode language: Bash (bash)
Once this command has completed, try running
nvm in your terminal. If you see the following, your install is successful!
How to Install nvm for Windows
The window version of nvm, called nvm-windows, uses similar commands to install and use as the Mac version.
Head over to the nvm-window releases page and download the most recent
nvm-setup.exe. Double click to run it and follow the instructions.
Once installed, you should be able to open up your command line of choice (PowerShell, cmd, etc) and run `nvm`.
❌ How to Install nvm with Homebrew
There is a Homebrew recipe for nvm, but don’t use it! The official docs even explicitly state this. You’ve been warned. ☠️
Homebrew installation is not supported. If you have issues with homebrew-installednvm-sh/nvm
brew uninstallit, and install it using the instructions below, before filing an issue.
Install Node Version
Once you’ve installed nvm and have confirmed it’s working, it’s time to install your desired version of Node.js!
If you’re like me, you might be thinking you’ll grab the latest version. That’s not always the best solution.
If you’re planning to deploy your Next.js application to Vercel, you should be aware they only support Node.js version 16.x and 18.x. The x refers to minor or patch version.
Even numbered Node versions like 16, 18 and 20 are considered stable. Odd versions like 17, 19 and 21 (the most current version) are considered in-progress.
As of this writing (November 16, 2023), I’d stick with Node.js 18. Even though it’s in “maintenance” right now according to this chart, it’s the highest version Vercel supports.
I’ve been working with Node.js since 1.0, and they’ve always provided a smooth upgrade path. I can’t remember ever upgrading Node and having it break something.
To see which versions you can install you can run:
nvm ls-remoteCode language: Bash (bash)
If you’re familiar with unix commands,
ls means list, and remote means remote. 😅 This will give a LONG list of every version of Node.js that’s ever been released.
If you scroll up, you’ll see every variant of Node.js 18.
If you were to run
nvm install 18 you’d install version 18.18.2 – the latest 18.x version.
nvm install 18
After this you should be able to check your Node version with
node -v and it’ll return “v18.18.2” (or whatever the latest version is).
v18.18.2Code language: CSS (css)
After that you’re set to start working with Node.js!
Setting Your Node Version
If you only have one version of Node.js installed, you’ll always use that one. Once you have two versions installed, you’ll want to set your default node version.
Let’s say you needed Node.js 16.x for another project. You’d install it the same way you installed v18:
You could then run
nvm ls to see all of your node versions.
These will also list out version names and aliases as well. You might find that useful. So far I’ve never needed anything except
default – which is the version that nvm will use when you restart.
You could switch to another version in blue right now with
nvm use 16Code language: PHP (php)
That would change your Node.js version to 16 for this session. If you wanted to change permanantly, you can change the alias by running.
If you run a
nvm ls after that, you’ll see
default now points to version 16.
There are many other commands we’re skipping over here including
nvm uninstall which will remove that Node.js version from your computer and unregister it from nvm. Run
nvm by itself to see a list of all commands.
The most common issue I’ve run into is getting the dreaded “nvm command not found” message. This means that nvm isn’t being loaded by your Terminal.
The first thing to try is to quit your terminal and reopen it. One of the scripts that nvm adds runs when you start your terminal and may not have been run.
If that doesn’t work
If you’re running into other problems, check out the Problems section of the nvm readme.
How to Update nvm?
The command to update nvm is the same as the command to install it. Just run it again.
How to Uninstall nvm?
nvm and all of your node versions are stored in a local directory, which is at
~/.nvm by default. You can delete the entire directory using the nvm’s variable to dynamically delete it (in case you installed it somewhere else.
The last step to uninstall nvm is a little more annoying. When you installed nvm, it added a few lines to your
~/.zshrc file. Look at the top of your terminal to see which it is. In my case it’s zsh. You can check at the top of your terminal to see.
Open up your
~/.zshrc file and remove the following lines:
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completionCode language: PHP (php)
I haven’t needed to uninstall it – except to reinstall it for this level. 😅
Next Step: Use nvm!
Now that you have nvm and a stable version of node installed, you’re all set to install packages from npm and build your application. See you in the next level. 👾