Home > Web Front-end > JS Tutorial > body text

How to upgrade node version? Detailed tutorial sharing

青灯夜游
Release: 2023-03-07 19:11:10
forward
6206 people have browsed it

如何升级node版本?下面本篇文章给大家总结分享详细的升级教程,介绍一下Window、Mac或Linux系统下升级node版本的方法,希望对大家有所帮助!

How to upgrade node version? Detailed tutorial sharing

Window 系统

PS C:\Users\liuxing> npm install -g n
npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for n@9.0.0: wanted {"os":"!win32","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! notsup Valid OS:    !win32
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   win32
npm ERR! notsup Actual Arch: x64

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\liuxing\AppData\Roaming\npm-cache\_logs\2022-11-03T09_24_21_102Z-debug.log
Copy after login

Mac 或 Linux系统

1、升级方法:以下命令如果提示没权限,请在命令的前面加上sudo,如sudo npm install n -g 【相关教程推荐:nodejs视频教程

  • 先清除npm缓存:

npm cache clean -f
Copy after login
  • 安装node版本管理工具n;

npm install n -g
Copy after login
  • 查看node 所有版本

npm view node versions
Copy after login

How to upgrade node version? Detailed tutorial sharing

  • 升级node版本

# 升级到指定的版本:n 版本号
n 16.0.0

# 升级到最新的稳定版本
n stable

# 升级到最新版本,不推荐
n latest
Copy after login
  • 使用node -v查看node版本,如果版本号改变为你想要的则升级成功。

node -v
16.0.0
Copy after login
Copy after login

2、如果版本号没变,可以重启机器或者尝试以下方法

  • 查看通过n安装的node的位置

which node
/usr/local/n/versions/node/16.0.0
Copy after login
  • 进入该位置

cd /usr/local/n/versions/node
Copy after login
  • 编辑/etc/profile

vim /etc/profile
Copy after login
  • 将node安装的路径,添加到文件末尾;

export NODE_HOME=/usr/local/n/versions/node/16.0.0
export PATH=$NODE_HOME/bin:$PATH
Copy after login
  • 输入wq退出保存文件,再编译/etc/profile;

source /etc/profile
Copy after login
  • 重新查看版本号

node -v
16.0.0
Copy after login
Copy after login

更多node相关知识,请访问:nodejs 教程

The above is the detailed content of How to upgrade node version? Detailed tutorial sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template