Fork me on GitHub

如何安装npm

此教程记录如何在Windows和Osx系统下安装npm

1 加入信任证书

1
$ npm config set cafile "/usr/local/share/ca-certificates/ca.graysoft.cn.crt"

2 创建base64用户名密码

创建base64用户名密码的命令,注意用实际的用户名,密码代替,不要尖括号,半角冒号分隔

1
$ echo -n '<username>:<password>' | openssl base64

3 修改文件

1
$ vi ~/.npmrc
1
2
3
4
5
6
7
registry=https://maven.graysoft.cn/content/groups/npm-all/
_auth=用前面命令产生的字符串替代
email=xxx@neutrey.com
always-auth=true
strict-ssl=false
loglevel=silly
cafile=/usr/local/share/ca-certificates/ca.graysoft.cn.crt

保存退出

参考 https://books.sonatype.com/nexus-book/reference/npm-deploying-packages.html

4 使用proxy

有些内网环境,例如现在公司内部需要配置代理服务器上网

1
npm config set proxy=http://[user]:[password]@[proxy_host]:[proxy_port]
1
2
npm config set proxy=http://192.168.3.11:3128
npm config set https-proxy=http://192.168.3.11:3128

当然也可以使用-g参数,作为全局设置。

0%