构建nodejs环境
总想留下点东西,不负年华!
00、download
release
https://nodejs.org/dist/ //all release
example
https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz
tar Jxf node-v6.10.3-linux-x64.tar.xz && mv node-v6.10.3-linux-x64 node-v6 && mv node-v6 /usr/local/
vi /etc/profile ###配置全局环境变量,真实的环境建议配置用户级别的变量,防止不可写
export NODE_HOME="/usr/local/node-v6"
export PATH=$NODE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$NODE_HOME/lib:$LD_LIBRARY_PATH
source /etc/profile
#查看版本
node -v
npm -v
01、配置代理及npm源
//配置代理
内网访问外网资源
npm config set proxy=http://127.0.0.1:8008
npm config set https-proxy http://127.0.0.1:8008 //https-->http
npm config set registry=http://registry.npm.taobao.org //注册npm
代理用户名和密码
npm config set proxy http://username:password@server:port
npm confit set https-proxy http://username:password@server:port
取消代理
npm config delete proxy
npm config delete https-proxy
临时使用
npm --registry https://registry.npm.taobao.org install express
持久使用
npm config set registry https://registry.npm.taobao.org
验证
npm config get registry
npm install forever -g
02、npm帮助命令
[root@VM_175_27_centos ~]# npm --help
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
help, help-search, i, init, install, install-test, it, link,
list, ln, login, logout, ls, outdated, owner, pack, ping,
prefix, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, tag, team, test, tst, un, uninstall,
unpublish, unstar, up, update, v, version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@3.10.10 /usr/local/node-v6/lib/node_modules/npm
[root@VM_175_27_centos ~]# npm config --help
npm config set <key> <value>
npm config get [<key>]
npm config delete <key>
npm config list
npm config edit
npm set <key> <value>
npm get [<key>]
npm config ls -l // to show all defaults.