本教程适用于centos, 这是ubuntu 教程 http://clock.co.uk/blog/how-to-create-a-private-npmjs-repository
安装之前
安装 Erlang
yum install gcc glibc-devel make ncurses-devel openssl-devel autoconf -y
wget http://erlang.org/download/otp_src_R15B01.tar.gz
tar zxvf otp_src_R15B01.tar.gz
cd otp_src_R15B01
./configure && make && sudo make install
开始安装npm私库
STEP 1 安装相关包
sudo yum install autoconf autoconf-archive automake curl-devel erlang-asn1 erlang-erts erlang-eunit erlang-os_mon erlang-xmerl help2man js-devel libicu-devel libicu-devel perl-Test-Harness -y
STEP 2. 安装 couchDB
STEP 2.1 下载 couchdb
sudo su -
$ wget http://mirrors.advancedhosters.com/apache/couchdb/source/1.6.0/apache-couchdb-1.6.0.tar.gz
$ tar xfv apache-couchdb-1.6.0.tar.gz
$ cd apache-couchdb-1.6.0
$ ./configure
$ make
$ make install
测试 couchdb
$ couchdb
Apache CouchDB 1.2.0 (LogLevel=info) is starting.
Apache CouchDB has started. Time to relax.
[info] [<0.32.0>] Apache CouchDB has started on http://127.0.0.1:5984/
成功之后 Ctrl+C 停止
STEP 2.2 创建 couchdb 用户
$ useradd couchdb
$ chown -R couchdb:couchdb /usr/local/var/{log,lib,run}/couchdb
$ chown -R couchdb:couchdb /usr/local/etc/couchdb
STEP 2.3 修改 couchdb 数据文件位置
$ mv /usr/local/var/lib/couchdb /data/
$ vim /usr/local/etc/couchdb/local.ini
增加以下内容
[couch_httpd_auth]
public_fields = appdotnet, avatar, avatarMedium, avatarLarge, date, email, fields, freenode, fullname, github, homepage, name, roles, twitter, type, _id, _rev
users_db_public = true
[httpd]
secure_rewrites = false
bind_address=0.0.0.0
[couchdb]
delayed_commits = false
database_dir = /data/couchdb
view_index_dir = /data/couchdb
STEP 2.4 增加自启动
$ touch /usr/local/var/run/couchdb/couchdb.pid
$ chown couchdb.couchdb /usr/local/var/run/couchdb/couchdb.pid
$ sudo ln -s /usr/local/etc/rc.d/couchdb /etc/init.d
$ chkconfig couchdb on
$ chkconfig --list | grep couchdb
couchdb 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$ service couchdb start
STEP 2.5 增加用户名密码(可选)
$ curl -X PUT http://localhost:5984/_config/admins/admin -d '"<password>"'
<password> 换成你想要的密码
比如:
$ curl -X PUT http://localhost:5984/_config/admins/admin -d '"123456"'
""
然后你去看local.ini文件就会发现多了一行
$ vim /usr/local/etc/couchdb/local.ini
[admins]
admin = -pbkdf2-297f2655663749cd6ff31d4f73dd973045501604,eaf253d41b0d8ddac87aa3d6683f7ee7,10
$ sudo /etc/init.d/couchdb restart
然后你测试一下添加一个库会告诉你没有权限
$ curl -X PUT http://localhost:5984/database2
{"error":"unauthorized","reason":"You are not a server admin."}
加上带用户名和密码的url再试一下
$ curl -X PUT http://admin:123456@localhost:5984/database2
{"ok":true}
STEP 3 设置npm私库
STE 3.1 复制 npmjs.org
第一个命令会非常久,因为会把整个npmjs.org 的库搬下来,所以请耐心等待,大概需要几个小时最长有可能要一天
$ curl -X POST http://127.0.0.1:5984/_replicate -d '{"source":"http://isaacs.iriscouch.com/registry/", "target":"registry", "create_target":true}' -H "Content-Type: application/json"
$ curl -X POST http://127.0.0.1:5984/_replicate -d '{"source":"http://isaacs.iriscouch.com/registry/", "target":"registry", "continuous":true, "create_target":true}' -H "Content-Type: application/json"
STEP 3.2 让 CouchDB 的镜像库工作起来
$ su -
$ npm install -g couchapp
$ git clone git://github.com/npm/npm-registry-couchapp
$ cd npm-registry-couchapp
$ npm install
$ npm start \
--npm-registry-couchapp:couch=http://localhost:5984/registry
检查以下是否应用上传完毕,这两步第一次运行也会比较久:
$ npm run load \
--npm-registry-couchapp:couch=http://localhost:5984/registry
$ npm --registry http://localhost:5984/registry/_design/scratch/_rewrite search
客户端设置
$ vim ~/.npmrc
增加以下这段registry = http://localhost:5984/registry/_design/scratch/_rewrite
上传自己的npm库到私库去
具体参见http://blog.youkuaiyun.com/nsrainbow/article/details/37903097