Node 是一個服務器端 JavaScript 解釋器,Node 自己運行 V8 JavaScript。V8 JavaScript 引擎是 Google 用於其 Chrome 瀏覽器的底層 JavaScript 引擎。php
NPM是隨同NodeJS一塊兒安裝的包管理工具,能解決NodeJS代碼部署上的不少問題,常見的使用場景有如下幾種:node
容許用戶從NPM服務器下載別人編寫的第三方包到本地使用。git
容許用戶從NPM服務器下載並安裝別人編寫的命令行程序到本地使用。github
容許用戶將本身編寫的包或命令行程序上傳到NPM服務器供別人使用。shell
因爲新版的nodejs已經集成了npm,因此以前npm也一併安裝好了。npm
nvm有點相似於 Python 的 virtualenv 或者 Ruby 的 rvm,php的composer,每一個node版本的模塊都會被安裝在各自版本的沙箱裏面(所以切換版本後模塊需從新安裝),所以考慮到須要時常對node版本進行切換測試兼容性和一些模塊對node版本的限制,對於node版本管理很方便瀏覽器
https://nodejs.org/
下載安裝包,osx下是一個pkg文件。bash
安裝成功提示:服務器
Node.js was installed at /usr/local/bin/node npm was installed at /usr/local/bin/npm Make sure that /usr/local/bin is in your $PATH.
這樣的話就不須要去刻意寫PATH,默認
/usr/local/bin/
,在osx的PATH中,若是沒有的話,那麼須要手動添加一個export PATH=/usr/local/bin:$PATH
到~/.bash_profile
裏面hexo
安裝成功後,打開終端
➜ git node -v v4.6.0 ➜ git npm -v 2.15.9
至此安裝完成
將nvm的git 庫clone到本地
$ cd ~/git $ git clone https://github.com/creationix/nvm.git //在本地建立一個存放git的目錄,而後git clone下到本地 source ~/git/nvm/nvm.sh //source這個腳原本初始化nvm的環境
備註:
在 ~/.bashrc, ~/.bash_profile, ~/.profile, 或者 ~/.zshrc 文件添加如下命令:source ~/git/nvm/nvm.sh
nvm 默認是從 http://nodejs.org/dist/ 下載的, 國外服務器, 必然很慢,咱們能夠更換國內的鏡像:
➜ git NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node nvm install 4 VERSION_PATH='' ######################################################################## 100.0% Computing checksum with shasum -a 256 Checksums matched! Now using node v4.6.0 (npm v2.15.9) Creating default alias: default -> 4 (-> v4.6.0)
寫在profile文件,自動加載,不用每次手動操做
cat ~/.bash_profile source ~/git/nvm/nvm.sh export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node
(這個也是須要將其寫進去profile文件的(~/.bashrc, ~/.bash_profile, ~/.profile, 或者 ~/.zshrc ,其中一個便可
))
安裝完成後檢查,第一次安裝nvm完成的時候會自動安裝一個最新版的node.js
➜ git nvm ls -> v4.6.0 system default -> 4 (-> v4.6.0) node -> stable (-> v4.6.0) (default) stable -> 4.6 (-> v4.6.0) (default) iojs -> N/A (default) lts/* -> lts/argon (-> v4.6.0) lts/argon -> v4.6.0
同理 nvm , npm 默認是從國外的源獲取和下載包信息,因此很慢,能夠經過簡單的 ---registry 參數, 使用國內的鏡像https://registry.npm.taobao.org
npm config set registry https://registry.npm.taobao.org/ npm install -g hexo //例如我這裏安裝一個hexo模塊 也能夠 npm --registry=https://registry.npm.taobao.org install -g hexo
備註:
npm的-g參數是安裝全局模塊
因爲淘寶已經中止了http的鏡像服務,安裝的時候,須要把
npm config set registry https://registry.npm.taobao.org
設置成https。
如例子所示,nvm use能夠切換node版本:
Example: nvm install v0.10.32 Install a specific version number nvm use 0.10 Use the latest available 0.10.x release nvm run 0.10.32 app.js Run app.js using node v0.10.32 nvm exec 0.10.32 node app.js Run `node app.js` with the PATH pointing to node v0.10.32 nvm alias default 0.10.32 Set default node version on a shell
參考:
https://cnodejs.org/topic/5338c5db7cbade005b023c98
http://www.eyrefree.org/2016/03/23/2016-03-23-Hexo-Coding-Pages/