Less than a month ago, iojs was released (multiple releases followed) and 6 days ago, the v0.12.0 of node was released.
I still had the same v0.10.x (can’t remember the patch 🙂 ) of node on my computer I installed a few months ago … As a nodejs developer, I decided it was time to get rid of my old version and switch to nvm so that I could test my projects (websites and node modules) on different engines and versions – moreover not to be stuck in the case some module should only work on one or an other …
This post is more a reminder for future me when I’ll make the install again, though it could help some people.
First, you’ll need Homebrew. If you’re a MacPorts user (or a Linux user), I assume it’s nearly the same, you may even have your own way which is faster and better, no need to troll 😉 – for Windows users, you have some alternatives.
Start by :
brew update
brew install nvm
mkdir ~/.nvm
nano ~/.bash_profile
In your .bash_profile
file (you may be using an other file, according to your shell), add the following :
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Back to your shell, activate nvm and check it (if you have other shells opened and you want to keep them, do the same) :
source ~/.bash_profile
echo $NVM_DIR
Now, you can install node :
nvm install 0.12
From now on, you’re using the v0.12.x of node on this shell, you can install your global dependencies such as grunt-cli (they will be tied up to this version of node).
You may want to install other versions, just do :
nvm install 0.10
nvm install iojs
...
You’ll have to npm install -g
your global dependencies for each version.
Switch of node version with nvm use 0.10
(more infos here).
To have a node activated by default (not to have to nvm use
on each new shell), run this (stable being the id of the version):
nvm alias default stable
Now, you can run multiple versions of node on your computer.
Sources :
For those using Visual Studio Code, you can use: sudo “/Applications/Visual Studio Code.app/Contents/MacOS/Electron” ~/.bash_profile to edit your bash_profile as admin using a GUI text editor
Thank you! You made my day.
Thank you, this worked well on High Sierra.
this worked perfectly
To make it work on ubuntu put export NVM_DIR=~/.nvm
source $(brew –prefix nvm)/nvm.sh in .bashrc instead of .bash_profile
same if you have an issue with brew path, run the code recommended code from a terminal to .bashrc instead of .bash_profile
Deference to op , some superb selective information .
Thanks for that. Clear and still valid.
This method will most likely not work anymore.
nvm states in their docs that “Homebrew installation is not supported.”
There’s an install instruction on the official git repo: https://github.com/nvm-sh/nvm
What’s up, all the time i used to check website posts
here early in the dawn, since i love to learn more and more.