admin 管理员组文章数量: 1184232
windows下Yarn安装
- windows下Yarn安装
- 方法一:使用安装包安装
- 方法二:使用npm安装
- 测试安装成功
- 配置配置 yarn 默认的缓存位置
- npm修改全局安装位置 和 缓存位置
- Yarn 修改全局安装位置 和 缓存位置
- 配置淘宝源
- 1. 配置淘宝源(加速,不喜欢也可以换)
- 2. 安装 yrm
- 常用命令
windows下Yarn安装
方法一:使用安装包安装
https://classic.yarnpkg/zh-Hans/docs/install#windows-stable
打开下载安装程序一路下一步
方法二:使用npm安装
npm i yarn -g
-i:install
-g:全局安装(global),使用 -g 或 --global
输入yarn -version 可以看到版本号,说明安装成功了。我们就可以在项目中像使用npm一样使用yarn了
测试安装成功
打开任意一个终端,cmd,cmder,powershell,git bash都可以
输入命令
yarn -version
成功显示版本,就说明安装成功了
yarn,是一款可以用来代替 npm 的包管理工具,你当然也可以用 npm 来安装 yarn,效果是一样的。
配置配置 yarn 默认的缓存位置
对于缓存在C盘不能忍的需要手动更改,参考下面的教程
npm修改全局安装位置 和 缓存位置
#1.改变npm 全局安装位置(示例)
npm config set prefix "你的磁盘路径"
#这里是我的路径
npm config set prefix "G:\Downloads\Nodejs\global"
#2. 改变 npm 缓存位置(示例)
npm config set cache "你的磁盘路径"
#这里是我的路径
npm config set cache "G:\Downloads\Nodejs\cache"
然后配置一下系统环境变量
D:\appCache\nodejs\node_global
D:\appCache\nodejs\node_global\node_modules 这两个添加到你的系统环境变量中。
检查是否修改成功命令
npm config ls
; "builtin" config from D:\Install\Nodejs\node_modules\npm\npmrc
; prefix = "C:\\Users\\admin\\AppData\\Roaming\\npm" ; overridden by user
; "user" config from C:\Users\admin\.npmrc
cache = "G:\\Downloads\\Nodejs\\cache"
prefix = "G:\\Downloads\\Nodejs\\global"
registry = "https://registry.npm.taobao/"
; "cli" config from command line options
omit = []
user-agent = "npm/7.0.14 node/v15.3.0 win32 x64"
; node bin location = D:\Install\Nodejs\node.exe
; cwd = C:\Users\admin
; HOME = C:\Users\admin
; Run `npm config ls -l` to show all defaults.
npm使用淘宝镜像
Yarn 修改全局安装位置 和 缓存位置
在CMD命令行中执行
#1.改变 yarn 全局安装位置(示例)
yarn config set global-folder "你的磁盘路径"
#2.然后你会在你的用户目录找到 `.yarnrc` 的文件,打开它,找到 `global-folder` ,改为 `--global-folder`
#这里是我的路径
yarn config set global-folder "G:\Downloads\Yarn\global"
#2. 改变 yarn 缓存位置(示例)
yarn config cache-folder "你的磁盘路径"
#这里是我的路径
yarn config set cache-folder "G:\Downloads\Yarn\cache"
在我们使用 全局安装 包的时候,会在 “G:\Downloads\Yarn\global” 下 生成 node_modules\.bin
目录 我们需要将 G:\Downloads\Yarn\global\node_modules\.bin 整个目录 添加到系统环境变量中去
否则通过yarn 添加的全局包 在cmd 中是找不到的。
检查当前yarn 的 bin的 位置
yarn global bin
检查当前 yarn 的 全局安装位置
yarn global dir
配置淘宝源
1. 配置淘宝源(加速,不喜欢也可以换)
yarn config set registry https://registry.npm.taobao/
2. 安装 yrm
yarn global add yrm
你也可以用
npm i -g yrm 来安装 yrm
列出所有镜像
yrm ls
npm ---- https://registry.npmjs/
cnpm --- http://rpmjs/
* taobao - https://registry.npm.taobao/
nj ----- https://registry.nodejitsu/
rednpm - http://registry.mirror.cqupt.edu/
npmMirror https://skimdb.npmjs/registry/
edunpm - http://registry.enpmjs/
yarn --- https://registry.yarnpkg
选择taobao镜像
yrm use taobao
YARN Registry has been set to: https://registry.npm.taobao/
verb config Skipping project config: C:\Users\roc/.npmrc. (matches userconfig)
NPM Registry has been set to: https://registry.npm.taobao/
常用命令
- yarn / yarn install 等同于npm install 批量安装依赖
- yarn add xxx 等同于 npm install xxx —save 安装指定包到指定位置
- yarn remove xxx 等同于 npm uninstall xxx —save 卸载指定包
- yarn add xxx —dev 等同于 npm install xxx —save-dev
- yarn upgrade 等同于 npm update 升级全部包
- yarn global add xxx 等同于 npm install xxx -g 全局安装指定包
版权声明:本文标题:windows下Yarn安装 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1767829468a3509014.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论