首页 > 代码库 > 如何建立npm私库
如何建立npm私库
本教程适用于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 [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 增加用户名密码(可选)
And while we are at it will lock down the application and prevent unauthorised users from deleting our data.$ vim /usr/local/etc/couchdb/local.ini [admins] admin=password $ sudo /etc/init.d/couchdb restart
看下进程,看couchdb是否正常启动
$ ps aux| grep couchdb couchdb 5511 0.0 0.0 9328 1448 ? S 09:38 0:00 /bin/sh -e /usr/local/bin/couchdb -a /usr/local/etc/couchdb/default.ini -a /usr/local/etc/couchdb/local.ini -b -r 5 -p /usr/local/var/run/couchdb/couchdb.pid -o /dev/null -e /dev/null -R couchdb 5521 0.0 0.0 9328 756 ? S 09:38 0:00 /bin/sh -e /usr/local/bin/couchdb -a /usr/local/etc/couchdb/default.ini -a /usr/local/etc/couchdb/local.ini -b -r 5 -p /usr/local/var/run/couchdb/couchdb.pid -o /dev/null -e /dev/null -R couchdb 5522 20.4 0.6 585268 51860 ? Sl 09:38 0:37 /usr/local/lib/erlang/erts-5.9.1/bin/beam.smp -Bd -K true -A 4 -- -root /usr/local/lib/erlang -progname erl -- -home /home/couchdb -- -noshell -noinput -os_mon start_memsup false start_cpu_sup false disk_space_check_interval 1 disk_almost_full_threshold 1 -sasl errlog_type error -couch_ini /usr/local/etc/couchdb/default.ini /usr/local/etc/couchdb/local.ini /usr/local/etc/couchdb/default.ini /usr/local/etc/couchdb/local.ini -s couch -pidfile /usr/local/var/run/couchdb/couchdb.pid -heart
如果修改完用户名密码之后无法启动,就暂时别修改了,我有时候会遇到增加了admin用户反而启动不了,暂时我也没找到解决方案
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":"registry2", "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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。