Using nvm
(Node Version Manager) will allow you to have multiple versions of Node on your machine. More importantly, it will prevent you from having to use sudo
when installing using npm install
.
-
Run the following commmand anywhere to install
nvm
:git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
-
Enable
nvm
on your system by edit the.bashrc
or.profile
file:vi ~/.bashrc
-
Paste the following into your open file. This will initialize the
nvm
environment every time your terminal loads:source ~/.nvm/nvm.sh
-
Either restart your terminal to make your
.bashrc
reload, or just use thesource
command:source ~/.bashrc
-
Use
nvm
to installnode
:nvm install 0.10
-
Tell
nvm
which version ofnode
to default to:nvm use 0.10 nvm alias default 0.10
Note: You can use
nvm ls-remote
to see the most current releases of node. -
To see a list of all the
node
versions you have installed:nvm ls
For advanced users: To make your current node and npm available for all the users on your machine (think VPS), run the following command:
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
This will take your current locally visible binaries and move them to /usr/local for everyone to see.
Click here for more info.