node.js安装


1. 下载

淘宝 Node.js 镜像 https://npmmirror.com/
https://registry.npmmirror.com/binary.html?path=node/
https://registry.npmmirror.com/binary.html?path=node/latest-v14.x/

wget https://npm.taobao.org/mirrors/node/v14.17.0/node-v14.17.0-linux-x64.tar.xz

2. 解压

tar -xf node-v14.17.0-linux-x64.tar.xz -C /usr/local
ln -s /usr/local/src/node-v14.17.0-linux-x64 /usr/local/nodejs

3. 添加命令到环境变量

ln -sf /usr/local/nodejs/bin/* /usr/local/bin/
# export PATH=/usr/local/nodejs/bin:$PATH

4. 测试

npm version
npx -v
node -v
npm config ls

5. 淘宝加速源配置

5.1 使用cnpm命令方式

路径兼容问题,有些情况可能会导致识别失败

npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm -v

5.2 使用命令行设置

npm config set registry https://registry.npm.taobao.org
npm config get registry
npm config set registry https://registry.npmjs.org  #恢复设置

### other
npm install phantomjs --phantomjs_cdnurl=http://npm.taobao.org/mirrors/phantomjs
npm install chromedriver --chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver
npm install operadriver --operadriver_cdnurl=http://npm.taobao.org/mirrors/operadriver
npm config set disturl https://npm.taobao.org/dist
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/

npm install -g yarn
yarn --version
yarn config list
yarn config set registry https://registry.npm.taobao.org

yarn config set disturl https://npm.taobao.org/dist -g
yarn config set electron_mirror https://npm.taobao.org/mirrors/electron/ -g
yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ -g
yarn config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/ -g
yarn config set chromedriver_cdnurl https://cdn.npm.taobao.org/dist/chromedriver -g
yarn config set operadriver_cdnurl https://cdn.npm.taobao.org/dist/operadriver -g
yarn config set fse_binary_host_mirror https://npm.taobao.org/mirrors/fsevents -g


## 镜像源设置
设置淘宝源: npm config set registry http://registry.npm.taobao.org/
撤销设置: npm config delete registry
切换回官方源: npm config set registry http://www.npmjs.org
或一次性使用   npm install --registry=https://registry.npm.taobao.org

5.3 修改配置文件

echo 'registry =https://registry.npm.taobao.org' > /usr/local/src/node-v14.17.0-linux-x64/lib/node_modules/npm/.npmrc

5.4 使用yarn

npm -g install yarn

image

PS

nvm node 多版本控制
https://www.npmmirror.com/

posted @ 2023-03-01 18:19  AlexG  阅读(19)  评论(0编辑  收藏  举报