nodejs如何將高版本降為低版本
nodejs高版本降為低版本
部分老舊項(xiàng)目需要使用低版本的node,網(wǎng)上很多是無(wú)效的,高版本無(wú)法直接安裝低版本node,但是低版本nodejs可以安裝部分高版本node,從而達(dá)到升級(jí)效果,下面這篇文章主要給大家介紹了關(guān)于nodejs高版本降為低版本的詳細(xì)解決方案,需要的朋友可以參考下
解決方案
1.首先通過(guò)控制面板應(yīng)用卸載當(dāng)前環(huán)境下的Node.js相關(guān)安裝,并清理磁盤(pán)殘存的文件夾等文件
2.下載nvm來(lái)管理node版本
官網(wǎng):https://github.com/coreybutler/nvm-windows/releases
這里我下載了 1.1.9 版本nvm,安裝node低版本是沒(méi)問(wèn)題的,但use nvm的時(shí)候報(bào)此問(wèn)題,查了各種原因,最后使用 1.1.7 以下版本成功解決
下載好安裝包之后,解壓直接運(yùn)行exe文件,選擇nvm和node的安裝路徑后一路next,然后打開(kāi)cmd,執(zhí)行 nvm -v
執(zhí)行 nvm ls available 查詢可用歷史版本
nvm npm_mirror https://npm.taobao.org/mirrors/npm/
配置淘寶鏡像 ,走國(guó)內(nèi)鏡速度更快,不會(huì)中斷失敗
然后安裝所需要的版本 ,執(zhí)行 nvm install node版本號(hào)
1.win+r->cmd->nvm -v 查看nvm版本,版本號(hào)是檢驗(yàn)時(shí)候安裝成功的標(biāo)志
2.常用nvm 命令
- nvm ls :列出所有已安裝的 node 版本
- nvm ls-remote :列出所有遠(yuǎn)程服務(wù)器的版本(官方node version list)
- nvm list :列出所有已安裝的 node 版本
- nvm list available :顯示所有可下載的版本
- nvm install stable :安裝最新版 node
- nvm install [node版本號(hào)] :安裝指定版本 node
- nvm uninstall [node版本號(hào)] :刪除已安裝的指定版本
- nvm use [node版本號(hào)] :切換到指定版本 node
- nvm current :當(dāng)前 node 版本
- nvm alias [別名] [node版本號(hào)] :給不同的版本號(hào)添加別名
- nvm unalias [別名] :刪除已定義的別名
- nvm alias default [node版本號(hào)] :設(shè)置默認(rèn)版本
nvm on // 啟用node.js版本管理 nvm off // 禁用node.js版本管理(不卸載任何東西)
若使用老的node.js且npm無(wú)法下載,npm需要手動(dòng)安裝
1.下載
方法一:在上圖中的綠框中的地址下載對(duì)應(yīng)的npm包
方法二:
- npm下載地址:http://npm.taobao.org/mirrors/npm/ (下載對(duì)應(yīng)版本的zip文件)
- node版本對(duì)應(yīng)npm版本:https://nodejs.org/zh-cn/download/releases/
2.將文件解壓到版本對(duì)應(yīng)的node_modules下,重名為npm
3.最后將npm文件夾里面的bin目錄下的npm和npm.cmd兩個(gè)文件復(fù)制一份到對(duì)應(yīng)node版本的根目錄下。
4.查看是否安裝成功
若npm -v出現(xiàn)版本號(hào),則安裝成功,若出現(xiàn)如下圖所示內(nèi)容,是因?yàn)樾遁dnode會(huì)卸載不干凈,需要手動(dòng)刪除npm相關(guān)文件夾,再使用npm install -g npm@版本號(hào) 下載所需版本
5.其他問(wèn)題
如果npm下載太慢,可通過(guò)配置國(guó)內(nèi)的淘寶鏡像提速
node中自帶npm,所以直接下載安裝nodejs即可,成功后設(shè)置npm為國(guó)內(nèi)的地址:
npm config set registry https://registry.npm.taobao.org
檢查一下:
npm config get registry
6.注意事項(xiàng):
npm、yarn 、rimraf(全局安裝:npm install rimraf -g指定目錄快速刪除node_modules:rimraf node_modules)都是放在指定版本的node文件下。
若更換node版本需要重新安裝指定版本的npm、yarn、rimraf
Microsoft Windows [版本 10.0.19044.3086] (c) Microsoft Corporation。保留所有權(quán)利。 C:\Users\Administrator>nvm -v 1.1.11 C:\Users\Administrator>nvm ls available | CURRENT | LTS | OLD STABLE | OLD UNSTABLE | |--------------|--------------|--------------|--------------| | 20.3.0 | 18.16.0 | 0.12.18 | 0.11.16 | | 20.2.0 | 18.15.0 | 0.12.17 | 0.11.15 | | 20.1.0 | 18.14.2 | 0.12.16 | 0.11.14 | | 20.0.0 | 18.14.1 | 0.12.15 | 0.11.13 | | 19.9.0 | 18.14.0 | 0.12.14 | 0.11.12 | | 19.8.1 | 18.13.0 | 0.12.13 | 0.11.11 | | 19.8.0 | 18.12.1 | 0.12.12 | 0.11.10 | | 19.7.0 | 18.12.0 | 0.12.11 | 0.11.9 | | 19.6.1 | 16.20.0 | 0.12.10 | 0.11.8 | | 19.6.0 | 16.19.1 | 0.12.9 | 0.11.7 | | 19.5.0 | 16.19.0 | 0.12.8 | 0.11.6 | | 19.4.0 | 16.18.1 | 0.12.7 | 0.11.5 | | 19.3.0 | 16.18.0 | 0.12.6 | 0.11.4 | | 19.2.0 | 16.17.1 | 0.12.5 | 0.11.3 | | 19.1.0 | 16.17.0 | 0.12.4 | 0.11.2 | | 19.0.1 | 16.16.0 | 0.12.3 | 0.11.1 | | 19.0.0 | 16.15.1 | 0.12.2 | 0.11.0 | | 18.11.0 | 16.15.0 | 0.12.1 | 0.9.12 | | 18.10.0 | 16.14.2 | 0.12.0 | 0.9.11 | | 18.9.1 | 16.14.1 | 0.10.48 | 0.9.10 | This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases C:\Users\Administrator> C:\Users\Administrator>node -v v18.14.0 C:\Users\Administrator>nvm npm_mirror https://npm.taobao.org/mirrors/npm/ C:\Users\Administrator>nvm insatll 14.19.2 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. C:\Users\Administrator>node -v v18.14.0 C:\Users\Administrator>nvm list * 18.14.0 (Currently using 64-bit executable) C:\Users\Administrator>nvm list available | CURRENT | LTS | OLD STABLE | OLD UNSTABLE | |--------------|--------------|--------------|--------------| | 20.3.0 | 18.16.0 | 0.12.18 | 0.11.16 | | 20.2.0 | 18.15.0 | 0.12.17 | 0.11.15 | | 20.1.0 | 18.14.2 | 0.12.16 | 0.11.14 | | 20.0.0 | 18.14.1 | 0.12.15 | 0.11.13 | | 19.9.0 | 18.14.0 | 0.12.14 | 0.11.12 | | 19.8.1 | 18.13.0 | 0.12.13 | 0.11.11 | | 19.8.0 | 18.12.1 | 0.12.12 | 0.11.10 | | 19.7.0 | 18.12.0 | 0.12.11 | 0.11.9 | | 19.6.1 | 16.20.0 | 0.12.10 | 0.11.8 | | 19.6.0 | 16.19.1 | 0.12.9 | 0.11.7 | | 19.5.0 | 16.19.0 | 0.12.8 | 0.11.6 | | 19.4.0 | 16.18.1 | 0.12.7 | 0.11.5 | | 19.3.0 | 16.18.0 | 0.12.6 | 0.11.4 | | 19.2.0 | 16.17.1 | 0.12.5 | 0.11.3 | | 19.1.0 | 16.17.0 | 0.12.4 | 0.11.2 | | 19.0.1 | 16.16.0 | 0.12.3 | 0.11.1 | | 19.0.0 | 16.15.1 | 0.12.2 | 0.11.0 | | 18.11.0 | 16.15.0 | 0.12.1 | 0.9.12 | | 18.10.0 | 16.14.2 | 0.12.0 | 0.9.11 | | 18.9.1 | 16.14.1 | 0.10.48 | 0.9.10 | This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases C:\Users\Administrator>node -v v18.14.0 C:\Users\Administrator>nvm current v18.14.0 C:\Users\Administrator>nvm uninstall 18.14.0 Uninstalling node v18.14.0... done C:\Users\Administrator>node -v 'node' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。 C:\Users\Administrator>nvm list No installations recognized. C:\Users\Administrator>nvm list available | CURRENT | LTS | OLD STABLE | OLD UNSTABLE | |--------------|--------------|--------------|--------------| | 20.3.0 | 18.16.0 | 0.12.18 | 0.11.16 | | 20.2.0 | 18.15.0 | 0.12.17 | 0.11.15 | | 20.1.0 | 18.14.2 | 0.12.16 | 0.11.14 | | 20.0.0 | 18.14.1 | 0.12.15 | 0.11.13 | | 19.9.0 | 18.14.0 | 0.12.14 | 0.11.12 | | 19.8.1 | 18.13.0 | 0.12.13 | 0.11.11 | | 19.8.0 | 18.12.1 | 0.12.12 | 0.11.10 | | 19.7.0 | 18.12.0 | 0.12.11 | 0.11.9 | | 19.6.1 | 16.20.0 | 0.12.10 | 0.11.8 | | 19.6.0 | 16.19.1 | 0.12.9 | 0.11.7 | | 19.5.0 | 16.19.0 | 0.12.8 | 0.11.6 | | 19.4.0 | 16.18.1 | 0.12.7 | 0.11.5 | | 19.3.0 | 16.18.0 | 0.12.6 | 0.11.4 | | 19.2.0 | 16.17.1 | 0.12.5 | 0.11.3 | | 19.1.0 | 16.17.0 | 0.12.4 | 0.11.2 | | 19.0.1 | 16.16.0 | 0.12.3 | 0.11.1 | | 19.0.0 | 16.15.1 | 0.12.2 | 0.11.0 | | 18.11.0 | 16.15.0 | 0.12.1 | 0.9.12 | | 18.10.0 | 16.14.2 | 0.12.0 | 0.9.11 | | 18.9.1 | 16.14.1 | 0.10.48 | 0.9.10 | This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases C:\Users\Administrator>nvm install 6.10.1 Downloading node.js version 6.10.1 (64-bit)... Complete Creating C:\nvm\temp Downloading npm version 3.10.10... Download failed. Rolling Back. C:\nvm\temp\npm-v3.10.10.zip Rollback failed. remove C:\nvm\temp\npm-v3.10.10.zip: The process cannot access the file because it is being used by another process. Could not download npm for node v6.10.1. Please visit https://github.com/npm/cli/releases/tag/v3.10.10 to download npm. It should be extracted to C:\nvm\v6.10.1 C:\Users\Administrator>node -v 'node' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。 C:\Users\Administrator>vue -v 'vue' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。 C:\Users\Administrator>npm info vue 'npm' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。 C:\Users\Administrator>nvm list available | CURRENT | LTS | OLD STABLE | OLD UNSTABLE | |--------------|--------------|--------------|--------------| | 20.3.0 | 18.16.0 | 0.12.18 | 0.11.16 | | 20.2.0 | 18.15.0 | 0.12.17 | 0.11.15 | | 20.1.0 | 18.14.2 | 0.12.16 | 0.11.14 | | 20.0.0 | 18.14.1 | 0.12.15 | 0.11.13 | | 19.9.0 | 18.14.0 | 0.12.14 | 0.11.12 | | 19.8.1 | 18.13.0 | 0.12.13 | 0.11.11 | | 19.8.0 | 18.12.1 | 0.12.12 | 0.11.10 | | 19.7.0 | 18.12.0 | 0.12.11 | 0.11.9 | | 19.6.1 | 16.20.0 | 0.12.10 | 0.11.8 | | 19.6.0 | 16.19.1 | 0.12.9 | 0.11.7 | | 19.5.0 | 16.19.0 | 0.12.8 | 0.11.6 | | 19.4.0 | 16.18.1 | 0.12.7 | 0.11.5 | | 19.3.0 | 16.18.0 | 0.12.6 | 0.11.4 | | 19.2.0 | 16.17.1 | 0.12.5 | 0.11.3 | | 19.1.0 | 16.17.0 | 0.12.4 | 0.11.2 | | 19.0.1 | 16.16.0 | 0.12.3 | 0.11.1 | | 19.0.0 | 16.15.1 | 0.12.2 | 0.11.0 | | 18.11.0 | 16.15.0 | 0.12.1 | 0.9.12 | | 18.10.0 | 16.14.2 | 0.12.0 | 0.9.11 | | 18.9.1 | 16.14.1 | 0.10.48 | 0.9.10 | This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases C:\Users\Administrator>nvm install 18.9.1 Downloading node.js version 18.9.1 (64-bit)... Extracting node and npm... Complete npm v8.19.1 installed successfully. Installation complete. If you want to use this version, type nvm use 18.9.1 C:\Users\Administrator>node -v 'node' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。 C:\Users\Administrator>node 'node' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序 或批處理文件。 C:\Users\Administrator>nvm current No current version. Run 'nvm use x.x.x' to set a version. C:\Users\Administrator>nvm -v 1.1.11 C:\Users\Administrator>nvm list 18.9.1 6.10.1 C:\Users\Administrator>nvm use 18.9.1 Now using node v18.9.1 (64-bit) C:\Users\Administrator>node -v v18.9.1 C:\Users\Administrator>nvm use 6.10.1 Now using node v6.10.1 (64-bit) C:\Users\Administrator>node -v v6.10.1 C:\Users\Administrator>nvm install 14.15.5 Downloading node.js version 14.15.5 (64-bit)... Complete Downloading npm version 6.14.11... Complete Installing npm v6.14.11... Installation complete. If you want to use this version, type nvm use 14.15.5 C:\Users\Administrator>nvm list 18.9.1 14.15.5 * 6.10.1 (Currently using 64-bit executable) C:\Users\Administrator>nvm use 14.15.5 Now using node v14.15.5 (64-bit) C:\Users\Administrator>node -v v14.15.5 C:\Users\Administrator>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Nodejs環(huán)境實(shí)現(xiàn)socket通信過(guò)程解析
這篇文章主要介紹了Nodejs環(huán)境實(shí)現(xiàn)socket通信過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07node.js實(shí)現(xiàn)微信JS-API封裝接口的示例代碼
這篇文章主要介紹了node.js實(shí)現(xiàn)微信JS-API封裝接口的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09json對(duì)象及數(shù)組鍵值的深度大小寫(xiě)轉(zhuǎn)換問(wèn)題詳解
這篇文章主要給大家介紹了關(guān)于json對(duì)象及數(shù)組鍵值的深度大小寫(xiě)轉(zhuǎn)換問(wèn)題的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03在koa中簡(jiǎn)單使用Websocket連接的方法示例
本文主要介紹了在koa中簡(jiǎn)單使用Websocket連接的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02Koa從零搭建到Api實(shí)現(xiàn)項(xiàng)目的搭建方法
這篇文章主要介紹了Koa從零搭建到Api實(shí)現(xiàn)項(xiàng)目的搭建方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07使用Node.js創(chuàng)建一個(gè)簡(jiǎn)單的HTTP服務(wù)器的示例代碼
Node.js 是一種強(qiáng)大的 JavaScript 運(yùn)行環(huán)境,允許開(kāi)發(fā)者在服務(wù)器端運(yùn)行 JavaScript 代碼,它以異步事件驅(qū)動(dòng)的方式處理大量連接,適合構(gòu)建高效的網(wǎng)絡(luò)應(yīng)用程序,在這篇文章中,我們將一起學(xué)習(xí)如何使用 Node.js 創(chuàng)建一個(gè)簡(jiǎn)單的 HTTP 服務(wù)器,并通過(guò)示例代碼幫你快速上手2025-02-02Node.js基礎(chǔ)入門(mén)之緩存區(qū)與文件操作詳解
Node.js是一個(gè)基于Chrome?V8引擎的JavaScript運(yùn)行時(shí)。類(lèi)似于Java中的JRE,.Net中的CLR。本文將詳細(xì)為大家介紹Node.js中的緩存區(qū)與文件操作,感興趣的可以了解一下2022-03-03node錯(cuò)誤處理與日志記錄的實(shí)現(xiàn)
這篇文章主要介紹了node錯(cuò)誤處理與日志記錄的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12koa2實(shí)現(xiàn)登錄注冊(cè)功能的示例代碼
這篇文章主要介紹了koa2實(shí)現(xiàn)登錄注冊(cè)功能的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12前端+nodejs+mysql實(shí)現(xiàn)前后端聯(lián)通的完整代碼
Node.js主要屬于后端技術(shù),但也可以用于前端開(kāi)發(fā)的某些場(chǎng)景,下面這篇文章主要介紹了前端+nodejs+mysql實(shí)現(xiàn)前后端聯(lián)通的完整代碼,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-04-04