在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

Node版本管理器:nvm

2016-12-20 13:17| 发布者: zhangjf| 查看: 574| 评论: 0

摘要: Node版本管理器:nvm。简单的bash脚本来管理多个活跃的node.js版本。Installation First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential an ...
Node版本管理器:nvm。简单的bash脚本来管理多个活跃的node.js版本。Installation

First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential and libssl-dev packages work.

Note: nvm does not support Windows (see #284). Two alternatives exist, which are not supported nor developed by us:

nvmw nvm-windows Install script

To install you could use the install script using cURL:

  1. curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
复制代码

or Wget:

  1. wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
复制代码

The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc or ~/.profile).

You can customize the install source, directory and profile using the NVM_SOURCE, NVM_DIR, and PROFILE variables. Eg: curl ... | NVM_DIR=/usr/local/nvm bash for a global install.

NB. The installer can use git, curl, or wget to download nvm, whatever is available.

Manual install

For manual install create a folder somewhere in your filesystem with the nvm.sh file inside it. I put mine in a folder called nvm.

Or if you have git installed, then just clone it, and check out the latest version:

  1. git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
复制代码

To activate nvm, you need to source it from your shell:

  1. source ~/.nvm/nvm.sh
复制代码

I always add this line to my ~/.bashrc, ~/.profile, or ~/.zshrc file to have it automatically sourced upon login. Often I also put in a line to use a specific version of node.

Usage

You can create an .nvmrc file containing version number in the project root directory (or any parent directory).nvm use, nvm install, nvm exec, and nvm run will all respect an .nvmrc file.

To download, compile, and install the latest v0.10.x release of node, do this:

  1. nvm install 0.10
复制代码

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

  1. nvm use 0.10
复制代码

Or you can just run it:

  1. nvm run 0.10 --version
复制代码

Or, you can run any arbitrary command in a subshell with the desired version of node:

  1. nvm exec 0.10 node --version
复制代码

In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":

  1. nvm install stable
  2. nvm install unstable
  3. nvm use stable
  4. nvm run unstable --version
复制代码

If you want to use the system-installed version of node, you can use the special default alias "system":

  1. nvm use system
  2. nvm run system --version
复制代码

If you want to see what versions are installed:

  1. nvm ls
复制代码

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

  1. nvm ls-remote
复制代码

To restore your PATH, you can deactivate it.

  1. nvm deactivate
复制代码

To set a default Node version to be used in any new shell, use the alias 'default':

  1. nvm alias default stable
复制代码

To use a mirror of the node binaries, set $NVM_NODEJS_ORG_MIRROR:

  1. export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
  2. nvm install 0.10
  3. NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install 0.10
复制代码

nvm use will not, by default, create a "current"symlink. Set $NVM_SYMLINK_CURRENT to "true" to enable this behavior, which is sometimes useful for IDEs.

项目主页:http://www.open-open.com/lib/view/home/1418097373136

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-8-19 02:14

Copyright 2015-2025 djqfx

返回顶部