一、NVM版本管理环境安装配置
1.nvm for windows安装包下载地址:
Releases · coreybutler/nvm-windows · GitHub
2.安装nvm
根据个人习惯下载setup或noinstall,setup包自动配置环境变量,加入系统PATH,如果下载noinstall包,解压到任意位置(惯例,路径不包含空格、特殊字符及中文),并配置环境变量。
注意:如果安装过程报错,请尝试使用管理员打开命令行
打开命令行,输入nvm -v指令,能显示版本号即可
C:\Users\Aidy>nvm -v
1.1.11
3.配置nvm
输入nvm -h,显示帮助
C:\Users\Aidy>nvm -h
Running version 1.1.11.
Usage:
nvm arch : Show if node is running in 32 or 64 bit mode.
nvm current : Display active version.
nvm debug : Check the NVM4W process for known problems (troubleshooter).
nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
Add --insecure to the end of this command to bypass SSL validation of the remote download server.
nvm list [available] : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
nvm on : Enable node.js version management.
nvm off : Disable node.js version management.
nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
Set [url] to "none" to remove the proxy.
nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
nvm uninstall <version> : The version must be a specific version.
nvm use [version] [arch] : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
"newest" is the latest installed version. Optionally specify 32/64bit architecture.
nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
nvm root [path] : Set the directory where nvm should store different versions of node.js.
If <path> is not set, the current root will be displayed.
nvm [--]version : Displays the current running version of nvm for Windows. Aliased as v.
常用命令:
nvm install:安装指定版本的node.js
nvm list:查看已安装的版本
nvm list available:查看远程可用版本
nvm node_mirror:设置node.js下载镜像地址,根据个人爱好设置,我一般使用阿里镜像
nvm node_mirror https://npmmirror.com/mirrors/node/
nvm use:选用已安装的版本
二、使用nvm安装node.js
1.查看可用的node.js版本
C:\Users\Aidy>nvm list available
| CURRENT | LTS | OLD STABLE | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
| 20.5.0 | 18.17.0 | 0.12.18 | 0.11.16 |
| 20.4.0 | 18.16.1 | 0.12.17 | 0.11.15 |
| 20.3.1 | 18.16.0 | 0.12.16 | 0.11.14 |
| 20.3.0 | 18.15.0 | 0.12.15 | 0.11.13 |
| 20.2.0 | 18.14.2 | 0.12.14 | 0.11.12 |
| 20.1.0 | 18.14.1 | 0.12.13 | 0.11.11 |
| 20.0.0 | 18.14.0 | 0.12.12 | 0.11.10 |
| 19.9.0 | 18.13.0 | 0.12.11 | 0.11.9 |
| 19.8.1 | 18.12.1 | 0.12.10 | 0.11.8 |
| 19.8.0 | 18.12.0 | 0.12.9 | 0.11.7 |
| 19.7.0 | 16.20.1 | 0.12.8 | 0.11.6 |
| 19.6.1 | 16.20.0 | 0.12.7 | 0.11.5 |
| 19.6.0 | 16.19.1 | 0.12.6 | 0.11.4 |
| 19.5.0 | 16.19.0 | 0.12.5 | 0.11.3 |
| 19.4.0 | 16.18.1 | 0.12.4 | 0.11.2 |
| 19.3.0 | 16.18.0 | 0.12.3 | 0.11.1 |
| 19.2.0 | 16.17.1 | 0.12.2 | 0.11.0 |
| 19.1.0 | 16.17.0 | 0.12.1 | 0.9.12 |
| 19.0.1 | 16.16.0 | 0.12.0 | 0.9.11 |
| 19.0.0 | 16.15.1 | 0.10.48 | 0.9.10 |
This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases
2.安装node.js
C:\Users\Aidy>nvm install 16.20.1
Downloading node.js version 16.20.1 (64-bit)...
Extracting node and npm...
Complete
npm v8.19.4 installed successfully.
Installation complete. If you want to use this version, type
nvm use 16.20.1
安装完成后查看
C:\Users\Aidy>nvm list
16.20.1
选择使用16.20.1
C:\Users\Aidy>nvm use 16.20.1
Now using node v16.20.1 (64-bit)
C:\Users\Aidy>nvm list
* 16.20.1 (Currently using 64-bit executable)
C:\Users\Aidy>npm -v
9.8.1
3.配置node.js
C:\Users\Aidy>npm config set registry https://registry.npmmirror.com/
C:\Users\Aidy>npm config set prefix e:\repos\npm\pkgs
使用阿里镜像地址
修改全局包路径(修改后将该路径加入系统环境变量PATH中)
安装cnpm及yarn管理工具
npm install -g cnpm
npm install -g yarn
4.修改国内镜像地址后出现的问题及解决方案
因国内网络环境的原因,使用npm默认镜像下载速度比较感人,所以一般使用国内镜像。
但是一旦使用国内镜像地址,会发现运行npm search xxx时无法搜索出结果,报404错误。
C:\Users\Aidy>npm search vue
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmmirror.com/-/v1/search?text=vue&size=20&from=0&quality=0.65&popularity=0.98&maintenance=0.5 - [NOT_FOUND] /-/v1/search not found
npm ERR! A complete log of this run can be found in: e:\repos\npm\cache\_logs\2023-08-07T03_37_04_923Z-debug-0.log
此时使用搜索功能时,必须携带参数,使用默认源镜像才可以,或者不配置全局镜像,每次安装使用--registry https://registry.npmmirror.com使用国内镜像
C:\Users\Aidy>npm search vue --registry https://registry.npmjs.org
NAME | DESCRIPTION | AUTHOR | DATE | VERSION | KEYWORDS
vue | The progressive… | =yyx990803… | 2023-05-18 | 3.3.4 | vue
vue-router | > - This is the… | =yyx990803… | 2023-07-06 | 4.2.4 |
vue-lazyload | Vue module for… | =imawe… | 2023-04-30 | 3.0.0 | vue-lazyload vue lazyload vue-directive
vue-resource | The HTTP client for… | =yyx990803… | 2021-06-14 | 1.5.3 | vue xhr http ajax
bootstrap-vue | With more than 85… | =xanf… | 2022-10-26 | 2.23.1 | Bootstrap Bootstrap v4 Bootstrap for Vue Vue Vue.js Vue v2 SSR Web Components Directives Icons Bootstrap Icons ARIA Accessibility a11y Popper.js CSS SCSS Alert Avatar Badge Brea
ant-design-vue | An enterprise-class… | =tangjinzhou | 2023-07-14 | 4.0.0 | vue vue3 ant design antd vueComponent component components ui framework frontend
eslint-plugin-vue | Official ESLint… | =yyx990803… | 2023-07-31 | 9.16.1 | eslint eslint-plugin eslint-config vue vuejs rules
vue-template-compiler | template compiler… | =posva… | 2022-11-09 | 2.7.14 | vue compiler
@coreui/vue | UI Components… | =coreui | 2023-07-16 | 4.10.0 | vue vue-component vue component vue bootstrap bootstrap vue ui library ui components component library components
vue-loader | > webpack loader… | =yyx990803… | 2023-06-02 | 17.2.2 |
vue-js-modal | Modal Component for… | =euvl | 2021-08-02 | 2.0.1 | front-end web vue vuejs vue-js dialog alert modal vue-js-modal vue-modal
tdesign-vue-next | TDesign Component… | =tdesign-bot | 2023-08-02 | 1.4.2 | vue vue3 vue-next tdesign typescript
vue-numeric | Input field… | =kevinongko | 2023-06-11 | 2.5.1 | component currency input text number numeric separator vue vue.js
swiper | Most modern mobile… | =nolimits4web | 2023-08-01 | 10.1.0 | swiper swipe slider touch ios mobile cordova phonegap app framework framework7 carousel gallery plugin react vue slideshow
@vue/compiler-sfc | @vue/compiler-sfc | =yyx990803 | 2023-05-18 | 3.3.4 | vue
generator-jhipster | Spring Boot +… | =danielfran… | 2023-07-12 | 8.0.0-b… | yeoman-generator Java Spring Spring Boot Spring Security JPA Hibernate React Angular Vue Twitter Bootstrap Webpack Docker JDL
vue-style-loader | Vue.js style loader… | =yyx990803… | 2021-03-03 | 4.1.3 |
sortablejs | JavaScript library… | =rubaxa =owenm | 2022-03-20 | 1.15.0 | sortable reorder drag meteor angular ng-sortable react vue mixin
element-ui | A Component Library… | =island205… | 2023-02-13 | 2.15.13 | eleme vue components
vux | Mobile web UI based… | =airyland… | 2021-09-17 | 2.11.1 | vux vue vue ui weui vue-components web-components component components mobile ui framework frontend
这样在使用的时候很不方便,当然,也可以使用cnpm解决,但是个人习惯,喜欢使用原汁原味的东西。
我的解决方案:
在上边配置的prefix(已加入系统变量PATH)或其他PATH路径下,创建批处理文件,内容如下:
@ECHO off
echo Run npm command with default registry
echo npm --registry https://registry.npmjs.org %1 %2
npm --registry https://registry.npmjs.org %1 %2
比如,我的批理命名为“snpm.cmd”
在使用的时候,直接用snpm search xxx即可。
当然,每个人习惯不同,根据个人喜好,能方便使用就行。
版权归原作者 孤狼行天下 所有, 如有侵权,请联系我们删除。