nvm npm cnpm nrm yarn pnpm

安装完node,cmd能运行npm,但是PowerShell无法运行 npm

get-executionpolicy
set-executionpolicy remotesigned

查看安装了哪些

npm list --depath=0 -g

nvm


作用

  • 进行nodejs版本控制

下载

  • https://github.com/coreybutler/nvm-windows/releases

安装

  • nvm-noinstall.zip: 这个是绿色免安装版本,但是使用之前需要配置

  • nvm-setup.zip:这是一个安装包,下载之后点击安装,无需配置就可以使用,方便。

  • Source code(zip):zip压缩的源码

  • Sourc code(tar.gz):tar.gz的源码,一般用于Linux系统

安装步骤属于傻瓜式操作,一直next就行了,在此不做截图演示

配置路径和下载源

在nvm安装路径下 setting.txt 文件中配置如下信息:
设置nvm路径(相当于setting.txt中的root:):
设置nodejs路径(相当于setting.txt中的path:):
node_mirror:npm.taobao.org/mirrors/node/
npm_mirror:npm.taobao.org/mirrors/npm/

测试

在电脑命令行输入nvm出现如下信息代表安装成功

image.png

安装 node npm

nvm install 12.13.0
nvm use 12.13.0
nvm uninstall 12.13.0
  • 安装使用后查看 nodenpm 版本

常用命令

命令 说明
nvm list 查看已经安装的版本
nvm list installed 查看已经安装的版本
nvm list available 查看网络可以安装的版本
nvm arch 查看当前系统的位数和当前nodejs的位数
nvm install [arch] 安装制定版本的node 并且可以指定平台 version 版本号 arch 平台
nvm on 打开nodejs版本控制
nvm off 关闭nodejs版本控制
nvm proxy [url] 查看和设置代理
nvm node_mirror [url] 设置或者查看setting.txt中的node_mirror,如果不设置的默认是 https://nodejs.org/dist/
nvm npm_mirror [url] 设置或者查看setting.txt中的npm_mirror,如果不设置的话默认的是 https://github.com/npm/npm/archive/.
nvm uninstall 卸载制定的版本
nvm use [version] [arch] 切换制定的node版本和位数
nvm root [path] 设置和查看root路径
nvm version 查看当前的版本

npm


// 全局npm

npm config set prefix "C:\dev\dev-tools\npm" // 修改npm的包的全局安装路径
npm config set cache "C:\dev\dev-tools\npm-cache" // 修改npm的包的全局cache位置
npm install npm -g // 全局安装npm

// 配置环境变量
在用户变量中添加 NPM_HOME=C:\dev\dev-tools\npm, path中添加%NPM-HOME%

常用命令

npm install xxx -g -D -S // g全局 D开发环境 S生产环境
npm uninstall xxx // 卸载依赖
npm config get registry// 查看下载源
npm config set registry https://registry.npmmirror.com // 修改为taobao源

cnpm


npm install -g cnpm --registry=http://r.cnpmjs.org
npm install -g cnpm --registry=https://registry.npm.taoba.org

nrm


作用

  • nrm(npm registry manager )是npm的镜像源管理工具,有时候国外资源太慢,使用这个就可以快速地在 npm 源间切换

安装

npm install nrm -g

使用

nrm ls
// bug: 不出现星号
// C:\dev\dev-tools\npm\node_modules\nrm\cli.js   && 改为 ||
if (hasOwnProperty(customRegistries, name) && (name in registries || customRegistries[name].registry === registry.registry)) {
  registry[FIELD_IS_CURRENT] = true;
  customRegistries[name] = registry;
}
if (hasOwnProperty(customRegistries, name) || (name in registries || customRegistries[name].registry === registry.registry)) {
  registry[FIELD_IS_CURRENT] = true;
  customRegistries[name] = registry;
}

image.png

yarn

安装

npm install yarn -g

yarn config get registry // 查看源
yarn config set registry https://registry.npmmirror.com // 修改为taobao源

yarn config list // 查看配置列表

yarn global bin //查看 yarn 全局bin位置(prefix)
yarn global dir // 查看 yarn 全局安装位置(folder)
yarn cache dir // 查看 yarn 全局cache位置(cache)

yarn config set prefix "C:\dev\dev-tools\npm\bin" // 改变 yarn 全局bin位置(prefix)
yarn config set global-folder "C:\dev\dev-tools\yarn" // 改变 yarn 全局安装位置(folder)
yarn config set cache-folder "C:\dev\dev-tools\yarn-cache" // 改变 yarn 全局cache位置(cache)

yarn init // 初始化

yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

yarn // 安装所有的依赖包
yarn install 

npm 与 yarn命令比较

image.png

pnpm

npm i -g pnpm // 安装

pnpm --version    // pnpm版本

pnpm cache list // 列出已缓存的每个包
pnpm cache dir // 返回全局缓存位置
pnpm cache clean // 清除缓存

pnpm config set store-dir "D:\dev\dev-tools\.pnpm-store" // pnpm全局仓库路径(类似 .git 仓库)
pnpm config set global-dir "D:\dev\dev-tools\pnpm-global" // pnpm全局安装路径
pnpm config set global-bin-dir "D:\dev\dev-tools\nodejs" // pnpm全局bin路径
pnpm config set state-dir "D:\dev\dev-tools\pnpm" // pnpm创建pnpm-state.json文件的目录
pnpm config set cache-dir "D:\dev\dev-tools\nodejs\pnpm\cache" // pnpm全局缓存路径

安装:

npm install -g @vue/cli
npm install -g webpack webpack-cli
npm i -g nodemon
npm i -g concurrently

你可能感兴趣的:(nvm npm cnpm nrm yarn pnpm)