使用npm可以很方便的安装各种Node模块,但是npm默认连接的镜像库在国外,致使我们安装模块时很慢,甚至出现卡死现象。
官方镜像
国内镜像
网站地址:https://npmmirror.com
Registry:https://registry.npmmirror.com
cnpmjs镜像
网站地址:http://cnpmjs.org
registry地址:http://r.cnpmjs.org
切换到国内镜像
1. 临时使用
npm --registry https://registry.npmmirror.com install xxxx
2. 永久使用
npm config set registry https://registry.npmmirror.com
3. 验证配置
npm config get registry
使用cnpm工具
1. 安装
npm install -g cnpm --registry=https://registry.npmmirror.com
2. 使用
cnpm install xxx
NPM INSTALL FOR CENTOS 7
1.安装gcc
yum install gcc gcc-c++
2.下载node国内镜像(推荐)
wget https://npm.taobao.org/mirrors/node/v16.8.0/node-v16.8.0-linux-x64.tar.gz
3.解压并重命名文件夹
tar -xvf node-v16.8.0-linux-x64.tar.gz mv node-v16.8.0-linux-x64 node
4.添加环境变量
vi /etc/profile
在文件最后添加以下配置:
export NODE_HOME=/usr/local/node export PATH=$NODE_HOME/bin:$PATH
5.刷新配置
source /etc/profile
6.验证结果
node -v npm -v
ERRORS
Node Sass version 6.0.1 is incompatible with ^4.0.0
cnpm uninstall node-sass cnpm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install node-sass@4.14.1
ERRORS
# gyp error # cnpm install -g npm # Cannot find module 'node-sass' # cnpm uninstall node-sass # cnpm install node-sass@4.14.1 # Node Sass version 6.0.0 is incompatible with^4.0.0 # cnpm uninstall node-sass # cnpm install node-sass@4.14.1 # Error: Node Sass does not yet support your current environment # cnpm rebuild node-sass # or # cnpm uninstall --save node-sass # cnpm cache clean -f # cnpm install --save node-sass # npm # npm uninstall node-sass # npm install -g cnpm --registry=https://registry.npm.taobao.org # npm install node-sass@4.14.1
查看通过 npm install -g xxx 安装的全局组件存放位置
npm config get prefix C:\Users\Administrator\AppData\Roaming\npm
.