NVM
2024年10月28日大约 6 分钟
NVM
1. nvm介绍
在工作中,可能同时在进行2个或者多个不同的项目开发,每个项目的需求不同,进而不同项目必须依赖不同版本的NodeJS运行环境,这种情况下,对于维护多个版本的node将会是一件非常麻烦的事情,nvm就是为解决这个问题而产生的,他可以方便的在同一台设备上进行多个node版本之间切换。
2. nvm下载安装配置
1. nvm下载
安装包下载地址:https://github.com/coreybutler/nvm-windows/releases,windows系统下载nvm-setup.zip安装包
2. nvm安装
- 同意
- 选择nvm安装目录
- nodejs目录
- 参看环境变量
参看版本:
3. nvm配置
- 参考
- https://github.com/coreybutler/nvm-windows
- https://blog.csdn.net/m0_46491549/article/details/129750694
打开安装目录后,直接编辑settings.txt即可
推荐新的淘宝镜像域名
node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/
#-----------------------------------------------------
或者使用命令行设置
nvm npm_mirror https://npmmirror.com/mirrors/npm/
nvm node_mirror https://npmmirror.com/mirrors/node/
3. nvm使用
nvm-windows 在 Admin shell 中运行。您需要以powershell管理员身份启动或命令提示符才能使用 nvm-windows
nvm arch [32|64]:显示节点是在 32 位还是 64 位模式下运行。指定 32 或 64 以覆盖默认架构。
nvm current: 显示活动版本。
nvm install <version> [arch]:版本可以是特定版本,“latest”表示最新的当前版本,或“lts”表示最新的 LTS 版本。可选地指定是安装 32 位还是 64 位版本(默认为系统架构)。将 [arch] 设置为“all”以安装 32 位和 64 位版本。添加--insecure到此命令的末尾以绕过远程下载服务器的 SSL 验证。
nvm list [available]:列出 node.js 安装。在末尾键入available以显示可供下载的版本列表。
nvm on: 启用 node.js 版本管理。
nvm off:禁用 node.js 版本管理(不卸载任何东西)。
nvm proxy [url]:设置用于下载的代理。留空[url]以查看当前代理。设置[url]为“无”以删除代理。
nvm uninstall <version>:卸载特定版本。
nvm use <version> [arch]:切换到使用指定的版本。可选择使用latest,lts或newest. newest是最新安装的版本。可选择指定 32/64 位架构。nvm use <arch>将继续使用所选版本,但切换到 32/64 位模式。有关use在特定目录中使用(或使用.nvmrc)的信息,请参阅问题 #16。
nvm root <path>: 设置 nvm 应该存放不同版本的 node.js 的目录。如果<path>未设置,将显示当前根目录。
nvm version:显示当前运行的 NVM for Windows 版本。
nvm node_mirror <node_mirror_url>:设置节点镜像。国内的人可以使用https://npmmirror.com/mirrors/node/
nvm npm_mirror <npm_mirror_url>:设置npm镜像。中国的人可以使用https://npmmirror.com/mirrors/npm/
- 举例
nvm list available
nvm install 16.15.0 64
nvm use 16.15.0 64
nvm current
4. npm配置
# 配置npm
npm config set prefix "D:\DevTools\webTools\npm\node_global"
npm config set cache "D:\DevTools\webTools\npm\node_cache"
# 配置系统环境变量 path中新增
D:\DevTools\webTools\npm\npm_global
D:\DevTools\webTools\npm\npm_global\bin
# 安装nrm 切换淘宝源
npm install -g nrm
nrm ls
nrm use taobao
npm config ls
# 安装less
npm install -g less
# 安装yarn https://yarn.bootcss.com/docs
npm install -g yarn
yarn --version
# yrm 切换淘宝源
npm install -g yrm
yrm ls
yrm use taobao
yrm test taobao
# 配置yarn 环境
yarn global dir
yarn config set global-folder "D:\DevTools\webTools\Yarn\yarn_global"
yarn config set cache-folder "D:\DevTools\webTools\Yarn\yarn_cache"
# 环境变量 path中新增:
D:\DevTools\webTools\Yarn\yarn_global\node_modules\.bin
#安装vue/cli
yarn global add @vue/cli@4.5.17
https://yarn.bootcss.com/docs/migrating-from-npm
windows-build-tools
https://download.microsoft.com/download/E/E/D/EEDF18A8-4AED-4CE0-BEBE-70A83094FC5A/BuildTools_Full.exe
npm install --global windows-build-tools
解决Git Bash中文乱码的问题
方法一
一、桌面右击,点击“Git Bash Here”
二、在弹出的黑窗口,右击,选择“options”
三、在弹出的窗口,选择“Text”,修改如下值后,先点击“Apply”,再点击“Save”
四、关闭窗口,重现打开“Git Bash”,再次输入命令,发现乱码已经解决
方法二
git bash命令设置支持中文字符
在git bash输入如下命令:
git config --global gui.encoding utf-8
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
export LESSCHARSET=utf-8
解决npm安装windows-build-tools时卡在Successfully installed Python 2.7
npm install --global windows-build-tools
解决npm安装windows-build-tools时卡在Successfully installed Python 2.7
如果你找到了这里,说明你之前看过的博文都是没有效果且没有任何意义的。因为我按照其他的教程试验了一下,根本没有任何效果。
这其实是windows-build-tools安装脚本的一个BUG,我在其github的issue中找到了这个
链接:https://github.com/felixrieseberg/windows-build-tools/issues/244
有兴趣的可以直接打开看原文,以下为我的翻译
“Windows-build-tools脚本存在问题,无法找到VS构建工具安装程序的日志文件。似乎VS构建工具安装程序创建的日志文件已更改。该脚本正在文件夹%USERPROFILE%\ AppData \ Local \ Temp中寻找名称以dd_client_开头的日志文件,但是VS构建工具安装程序似乎并未创建任何以dd_client_开头的文件。”
解决步骤:
1、运行npm install -g windows-build-tools
2、在%temp%文件夹中找到最新的文件名类似于dd_installer_20210421124746.log的文件
3、查看此文件,确保日志中输出了Closing the installer with exit code 0
4、确保你安装了vscode
ps:其实可以直接跳过2–4步,因为你的python环境早就安装好了,重复的步骤安装程序早就执行完毕了
5、在%temp%目录下创建一个名为dd_client_.log的文件
6、编辑5中创建的文件,加入一行Closing installer. Return code: 3010.然后保存。
然后windows-build-tools就可以继续安装了
注:直接在资源管理器中粘贴%temp%即可打开你的Windows temp目录。
————————————————
版权声明:本文为CSDN博主「FencingMan-X」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/oqzuser1234asd/article/details/116169889
git--解决exited with error code: 128: elementuiadmin
原因分析
有的库有改动,不能通过git://访问了,这时我们可以改为使用https://来访问。
解决方案
在请求git://地址时,自动替换为https://,命令如下:
git config --global url."https://".insteadOf git://
执行完上边的命令之后,再执行npm install,就能成功了:
备注
如果想删除这个设置,命令如下:
git config --global unset url."https://".insteadOf
url.<base>.insteadOf详解
官网:https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf
yarn config set ignore-engines true
commander@9.4.0: The engine "node" is incompatible with this module. Expected version "^12.20.0 || >=14". Got "10.24.1"
解决方案(2个)
方案1:卸载node重装指定版本范围的
方案2:忽略错误后重新yarn install
执行
yarn config set ignore-engines true
为了省事,我采用的是方案2