使用 Chocolatey 安装 Yarn 是一个非常简单的过程。以下是详细的步骤:
步骤 1:确保已经安装了 Chocolatey
使用 Windows PowerShell (管理员) 安装 Chocolatey:https://blog.csdn.net/m0_65152767/article/details/143783103?spm=1001.2014.3001.5502
步骤 2:使用 Chocolatey 安装 Yarn
-
打开 PowerShell 作为管理员:
- 按
Win + X键。 - 选择
Windows PowerShell (管理员)或Windows Terminal (管理员)。
- 按
-
运行安装命令:
choco install yarnWindows PowerShell 版权所有 (C) Microsoft Corporation。保留所有权利。 尝试新的跨平台 PowerShell https://aka.ms/pscore6 PS C:\WINDOWS\system32> choco install yarn Chocolatey v2.4.0 Installing the following packages: yarn By installing, you accept licenses for the packages. Downloading package from source 'https://community.chocolatey.org/api/v2/' Progress: Downloading yarn 1.22.22... 100% yarn v1.22.22 [Approved] yarn package files install completed. Performing other installation steps. The package yarn wants to run 'chocolateyinstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): y Using system proxy server '127.0.0.1:7890'. Downloading yarn from 'https://yarnpkg.com/downloads/1.22.22/yarn-1.22.22.msi' Using system proxy server '127.0.0.1:7890'. Progress: 100% - Completed download of C:\Users\dgq\AppData\Local\Temp\chocolatey\yarn\1.22.22\yarn-1.22.22.msi (1.59 MB). Download of yarn-1.22.22.msi (1.59 MB) completed. Hashes match. Installing yarn... yarn has been installed. 0 yarn may be able to be automatically uninstalled. Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type `refreshenv`). The install of yarn was successful. Software installed as 'msi', install location is likely default. Chocolatey installed 1/1 packages. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). Did you know the proceeds of Pro (and some proceeds from other licensed editions) go into bettering the community infrastructure? Your support ensures an active community, keeps Chocolatey tip-top, plus it nets you some awesome features! https://chocolatey.org/compare -
等待安装完成:
- 安装过程可能需要几分钟时间,耐心等待。
-
验证安装:
- 运行以下命令来验证 Yarn 是否安装成功:
yarn --version - 如果安装成功,你会看到 Yarn 的版本号。
- 运行以下命令来验证 Yarn 是否安装成功:
示例步骤
以下是完整的示例步骤:
-
确保已经安装了 Chocolatey:
- 打开 PowerShell 作为管理员。
- 运行以下命令:
choco -v - 如果输出显示 Chocolatey 的版本号,说明 Chocolatey 已经安装成功。
-
使用 Chocolatey 安装 Yarn:
- 打开 PowerShell 作为管理员。
- 运行以下命令:
choco install yarn
-
等待安装完成:
- 安装过程可能需要几分钟时间,耐心等待。
-
验证安装:
-
运行以下命令:
yarn --versionPS C:\WINDOWS\system32> yarn --version 1.22.22 PS C:\WINDOWS\system32> -
如果安装成功,你会看到 Yarn 的版本号。
-
其他注意事项
C:\Users\dgq>where yarn
D:\Java\node-v16.13.2-win-x64\node-v16.13.2-win-x64\yarn
D:\Java\node-v16.13.2-win-x64\node-v16.13.2-win-x64\yarn.cmd
C:\Program Files (x86)\Yarn\bin\yarn
C:\Program Files (x86)\Yarn\bin\yarn.cmd
C:\Program Files (x86)\Yarn\bin\yarn.js
-
确保 PATH 环境变量正确配置:
- 如果你遇到
yarn命令无法识别的问题,可以手动检查和修改 PATH 环境变量。 - 打开“系统属性” -> “高级” -> “环境变量”,在“系统变量”部分找到
Path变量,确保包含 Yarn 的安装路径(通常是C:\ProgramData\chocolatey\bin)。
- 如果你遇到
-
重新启动命令提示符或 PowerShell:
- 安装完成后,建议重新启动命令提示符或 PowerShell 以确保所有环境变量更新生效。
通过以上步骤,你应该能够成功使用 Chocolatey 安装 Yarn 并验证安装是否成功。

1494

被折叠的 条评论
为什么被折叠?



