nvm – Node Version Manager

Nhân dịp update node version lên bản v0.10.21 (http://blog.nodejs.org/2013/10/18/node-v0-10-21-stable/)

1. nvm là gì?

Là chương trình dùng để quản lý version của Node.js . HP: https://github.com/creationix/nvm

2.Cài đặt nvm trên Mac OS

tuan@tmac ~ $git clone git://github.com/creationix/nvm.git ~/.nvm
tuan@tmac ~ $ source ~/.nvm/nvm.sh
tuan@tmac ~ $ // .bashrc or .bash_profile
[[ -s USER_HOME/.nvm/nvm.sh ]] && . USER_HOME/.nvm/nvm.sh
nvm use default
npm_dir=${NVM_PATH}_modules
export NODE_PATH=$npm_dir

3. Sử dụng


tuan@tmac ~ $ nvm
Node Version Manager
Usage:
nvm help Show this message
nvm install [-s] <version> Download and install a <version>
nvm uninstall <version> Uninstall a version
nvm use <version> Modify PATH to use <version>
nvm run <version> [<args>] Run <version> with <args> as arguments
nvm ls List installed versions
nvm ls <version> List versions matching a given description
nvm ls-remote List remote versions available for install
nvm deactivate Undo effects of NVM on current shell
nvm alias [<pattern>] Show all aliases beginning with <pattern>
nvm alias <name> <version> Set an alias named <name> pointing to <version>
nvm unalias <name> Deletes the alias named <name>
nvm copy-packages <version> Install global NPM packages contained in <version> to current version
Example:
nvm install v0.4.12 Install a specific version number
nvm use 0.2 Use the latest available 0.2.x release
nvm run 0.4.12 myApp.js Run myApp.js using node v0.4.12
nvm alias default 0.4 Auto use the latest installed v0.4.x version

3.Cài đặt node.js

List tất cả các version có thể cài đặt được.

tuan@tmac ~ $ nvm ls-remote
tuan@tmac ~ $ nvm install 0.10.21
######################################################################## 100.0%
-f: move to trash.
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
/Users/tuan/.nvm/bin/node-v0.10.21-darwin-x64/node-v0.10.21-darwin-x64.tar.gz: move to trash.
Now using node v0.10.21

4.Chạy node.js với version chỉ định


tuan@tmac ~ $nvm use v0.10.21
tuan@tmac ~ $node -v
v0.10.21

5.Thiết định version mặc định


tuan@mac ~$nvm alias use default  v0.10.21