如何使用nvm管理多个本地安装的node.js?

时间:2021-09-26 15:15:17

I already have multiple node.js versions installed locally in my x-Linux box, 0.10.40, 0.12.7 and 4.0

我已经在我的x-Linux盒子里安装了多个node.js版本,0.10.40,0.12.7和4.0

My default profile is pointing to node.js 0.12.7 Currently, I set my PATH to point to different versions of node when I start a new terminal.

我的默认配置文件指向node.js 0.12.7目前,当我启动一个新终端时,我将PATH设置为指向不同版本的节点。

I would like to use node version manager to use and manage different version of node that is already installed in my environment .

我想使用节点版本管理器来使用和管理我环境中已安装的不同版本的节点。

How should I do it without reinstalling node again?

如果不重新安装节点,我该怎么做?

2 个解决方案

#1


3  

Answering Original Post

For the small amount of data that you'd save by doing the following, it's almost not worth it. That being said...

对于通过执行以下操作而节省的少量数据,几乎不值得。话虽如此...

Find where current versions are stored in nvm:

查找当前版本在nvm中的存储位置:

> nvm which
# mac
/Users/[username]/.nvm/versions/node/[version]/bin/node
# linux
/home/[username]/.nvm/versions/node/[version]/bin/node

Find all your non-nvm installed versions of node:

找到所有非nvm安装的节点版本:

> which -a node

(..pending how you are running each of your terminals for each version of node installed will tell how effective this command will be).

(..为每个安装的节点版本运行每个终端的方式将告诉你这个命令的效果如何)。

Then symbolic link each of them to a folder matching the version.

然后将它们中的每一个符号链接到与版本匹配的文件夹。

> ln -s /path/to/node/version ~/.nvm/versions/node/[version]
# `$HOME` or `~/` or `/Home/username/` ... you know which works.

Node and Version Swapping Made Simple

nvm-controlled versions of node installed

已安装nvm控制的节点版本

> nvm ls
       v0.10.33
       v0.10.36
       v0.10.40
         v4.0.0
         v4.2.2
         v5.0.0
->       v5.1.1
         system
default -> v5.1.1
system -> v5.1.1
node -> stable (-> v5.1.1) (default)
stable -> 5.1 (-> v5.1.1) (default)
iojs -> N/A (default)

Install version x, x.y, or x.y.z: nvm install x.y.z. ie:

安装版本x,x.y或x.y.z:nvm install x.y.z.即:

> nvm install 4.2.2

# If you want all modules from another version too:
> nvm install 4.2.2 --reinstall-packages-from=0.10.40

Set the default version used:

设置使用的默认版本:

> nvm use 5.1.1

# But if only a local node command required, use:
# nvm exec [version] [command]
> nvm exec 0.10.33 node server.js

.nvmrc file in project root to define which local version of node to use.

项目根目录中的.nvmrc文件,用于定义要使用的节点的本地版本。

#.nvmrc file contents:
5.1.1

#2


0  

You can't using installed nodejs version with nvm, Because nvm use own directory for managing versions

您不能将已安装的nodejs版本与nvm一起使用,因为nvm使用自己的目录来管理版本

You just need reinstall node versions

您只需要重新安装节点版本

nvm install 0.12.7

And then

接着

nvm use 0.12.7

#1


3  

Answering Original Post

For the small amount of data that you'd save by doing the following, it's almost not worth it. That being said...

对于通过执行以下操作而节省的少量数据,几乎不值得。话虽如此...

Find where current versions are stored in nvm:

查找当前版本在nvm中的存储位置:

> nvm which
# mac
/Users/[username]/.nvm/versions/node/[version]/bin/node
# linux
/home/[username]/.nvm/versions/node/[version]/bin/node

Find all your non-nvm installed versions of node:

找到所有非nvm安装的节点版本:

> which -a node

(..pending how you are running each of your terminals for each version of node installed will tell how effective this command will be).

(..为每个安装的节点版本运行每个终端的方式将告诉你这个命令的效果如何)。

Then symbolic link each of them to a folder matching the version.

然后将它们中的每一个符号链接到与版本匹配的文件夹。

> ln -s /path/to/node/version ~/.nvm/versions/node/[version]
# `$HOME` or `~/` or `/Home/username/` ... you know which works.

Node and Version Swapping Made Simple

nvm-controlled versions of node installed

已安装nvm控制的节点版本

> nvm ls
       v0.10.33
       v0.10.36
       v0.10.40
         v4.0.0
         v4.2.2
         v5.0.0
->       v5.1.1
         system
default -> v5.1.1
system -> v5.1.1
node -> stable (-> v5.1.1) (default)
stable -> 5.1 (-> v5.1.1) (default)
iojs -> N/A (default)

Install version x, x.y, or x.y.z: nvm install x.y.z. ie:

安装版本x,x.y或x.y.z:nvm install x.y.z.即:

> nvm install 4.2.2

# If you want all modules from another version too:
> nvm install 4.2.2 --reinstall-packages-from=0.10.40

Set the default version used:

设置使用的默认版本:

> nvm use 5.1.1

# But if only a local node command required, use:
# nvm exec [version] [command]
> nvm exec 0.10.33 node server.js

.nvmrc file in project root to define which local version of node to use.

项目根目录中的.nvmrc文件,用于定义要使用的节点的本地版本。

#.nvmrc file contents:
5.1.1

#2


0  

You can't using installed nodejs version with nvm, Because nvm use own directory for managing versions

您不能将已安装的nodejs版本与nvm一起使用,因为nvm使用自己的目录来管理版本

You just need reinstall node versions

您只需要重新安装节点版本

nvm install 0.12.7

And then

接着

nvm use 0.12.7