第一步:安裝Erlang環境
首先,安裝必要的庫
| yum install build-essential yum install libncurses5-dev yum install libssl-dev yum install m4 yum install unixodbc unixodbc-dev yum install freeglut3-dev libwxgtk2.8-dev yum install xsltproc yum install fop yum install tk8.5 yum install ncurses-devel yum install zip yum install libicu-devel |
編譯安裝Erlang環境
| tar –zxvf otp_src_R16B.tar.gz cd otp_src_R16B ./configure make make install |
驗證是否安裝成功
輸入erl
第二步:安裝CouchDB
解壓編譯安裝CouchDB
| tar –zxvf apache-couchdb-1.5.0.tar.gz cd apache-couchdb-1.5.0 make & make install |
CouchDB的安裝還需要依賴Mozilla的SpiderMonkey來執行一些javascript代碼
| wget http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz tar –zxvf js185-1.0.0 autoconf-2.13 ./configure make make install 配置環境變量 export LD_LIBRARY_PATH=/usr/local/lib |
啟動CouchDB
| ./couchdb & curl –I http://127.0.0.1:5984/ |
第三步:搭建NPM倉庫
- 創建NPM數據庫。首先,我們需要調用CouchDB的接口為創建一個數據庫,之后所有的模塊包文件將作為保存在這個數據庫中。
curl –X PUT http://127.0.0.1:5984/registry
- 獲取NPM倉庫源代碼。相關命令如下:
git clone https://github.com/isaacs/npmjs.org.git
cd npmjs.org
- 獲取安裝工具。
sudo npm install couchapp –g
npm install couchapp
npm install semver
- 裝在NPM倉庫代碼到CouchDB中
couchapp push registery/app.js http://127.0.0.1:5984/registry
Preparing.
Serializing.
PUT http://127.0.0.1:5984/registry/_design/scratch
Finished push. 1-4dd18325b8d8c5e60d….
couchapp push www/app.js http://127.0.0.1:5984/registry
PUT http://127.0.0.1:5984/registry/_design/ui
- 配合NPM客戶端。任意需要從本地NPM倉庫進行操作的命令,只要加入—registry=http://127.0.0.1:5984/registry/_design/scratch/_rewrite即可。
npm install plusplus –registry=http://127.0.0.1:5984/registry/_design/scratch/_rewrite
為了解決命令行過長不容易牢記的問題,可以使用如下方法:
npm config set registry http://127.0.0.1:5984/registry/_design/scratch/_rewrite
這個方法的一個問題在於,如果經常需要在官方倉庫和本地倉庫切換,那就比較麻煩。為此,我們可以利用bash中的alias功能來解決這個問題。在~/.profile文件的結尾處添加如下這行代碼:
alias lnpm=’npm –registry=http://127.0.0.1:5984/registry/_design/scratch/_rewrite’
重新啟動命令行,npm操作的是官方倉庫,lnpm操作的則是本地倉庫。其余參數和命名均相同。
第四步:應用
- 鏡像倉庫
- 私有模塊應用
- 純私有倉庫
