欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nvm (mac os x)

程序员文章站 2024-01-17 19:34:22
...

First, you’ll need Homebrew.

install

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’ll have to npm install -g your global dependencies for each version.
Switch of node version with nvm use 0.12
(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.

Usage

start a node shell

node

to Exit

ctrl + d

To download, compile, and install the latest release of node, do this(the latest version of node is 7.9 for 04/2017):

nvm install node

And then in any new shell just use the installed version:

nvm use node

Or you can just run it:

nvm run node --version

You can also get the path to the executable to where it was installed:

nvm which 7.9

node: this installs the latest version of node
.
stable: this alias is deprecated, and only truly applies to node v0.12 and earlier. Currently, this is an alias for node.

Listing versions

If you want to see what versions are installed:

nvm ls

If you want to see what versions are available to install:

nvm ls-remote
install Multiple Versions of Node.js

One of the most important parts of nvm is, of course, installing different versions of Node.js. For this, nvm provides the nvm install command. You can install specific versions by running this command followed by the version you want. For example:

nvm install 6.10.2   //(Latest LTS: Boron)

By running the above in a terminal, nvm will install Node.js version 6.10.2. nvm follows SemVer, so if you want to install, for example, the latest 6.10 patch, you can do it by running:

nvm install 6.10

source
http://dev.topheman.com/install-nvm-with-homebrew-to-use-multiple-versions-of-node-and-iojs-easily/
https://github.com/creationix/nvm/blob/master/README.markdown
https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/