nodejs升级到最新LTS版本方法汇总:linux/mac/window—npm/yum/ssh
nodejs不同版本的差异还是蛮多的,比如obj?.a 在nodejs12是不支持的,必须得升级到14才可以。但是centos yum 默认安装的,或者系统集成的nodejs版本都是很老的。项目上传到生产环境无法跑。所以,第一个是在项目中,锁定nodejs版本,比如:
{ "name": "bk-vision", "version": "0.2.7", "private": true, "description": "bk-vision", "keywords": [ "bk-vision", "可视化平台" ], "engines": { "node": "^v16.15.0", "npm": "^8.5.5" }, "main": "dist/main.js", }
本地nodejs版本管理,请参考:《nvm使用详解——命令解析大全》、《npm包管理问题:安装nvm后如何管理各个版本间包》
本篇主要讲linux 服务器上 升级方法,nodejs版本、
看了官网的文档:https://www.linode.com/docs/guides/how-to-update-nodejs/ 本篇做最详细的补充
通过npm升级npm和node升级的正确方式
npm升级npm
1 | npm install npm@latest -g |
检查 npm 的当前版本,使用命令:npm -v
清除npm cache
1 | npm cache clean -f |
npm升级nodejs
安装 n 模块
1 | npm install -g n |
安装最新的稳定版本
1 | n stable |
你也可以定制一个自己喜欢的版本:n 16.5.0
n – Interactively Manage Your Node.js Versions
https://www.npmjs.com/package/n
因为n比nvm简单,所以在linux上直接npm 来升级nodejs,我选择n
通过brew 更新 Node.js version on macOS
1 2 | brew update brew upgrade node |
yum安装新版nodejs
1 2 3 4 | yum clean all rm -fv /etc/yum .repos.d /nodesource * curl --silent --location https: //rpm .nodesource.com /setup_16 .x | sudo bash sudo yum -y install nodejs |
curl bash 做了什么?
curl表示获取地址对应的内容,而https://rpm.nodesource.com/setup_14.x就是一段shell脚步:
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash SCRSUFFIX= "_14.x" NODENAME= "Node.js 14.x" NODEREPO= "pub_14.x" NODEPKG= "nodejs" print_status() { local outp=$( echo "$1" ) # | sed -r 's/\n/\n## /mg') echo echo -e "## ${outp}" echo } ##省略 |
而|是管道符,表示通过bash执行上述shell脚步内容,脚步对yum的node源地址做了一些修改和设置
curl哪个nodejs版本?
具体查看:https://github.com/nodesource/distributions,查找 Installation instructions,
Node.js v14.x:
1 2 3 4 5 6 | # Using Ubuntu curl -fsSL https: //deb .nodesource.com /setup_14 .x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https: //deb .nodesource.com /setup_14 .x | bash - apt-get install -y nodejs |
Node.js LTS (v16.x):
1 2 3 4 5 6 | # Using Ubuntu curl -fsSL https: //deb .nodesource.com /setup_lts .x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https: //deb .nodesource.com /setup_lts .x | bash - apt-get install -y nodejs |
转载本站文章《nodejs升级到最新LTS版本方法汇总:linux/mac/window—npm/yum/ssh》,
请注明出处:https://www.zhoulujun.cn/html/webfront/ECMAScript/nodejs/8825.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了