简体   繁体   English

在 Ubuntu 上更新 Node.js - 更新后版本未更改

[英]Updating Node.js on Ubuntu - version not changed after update

I'm trying to update Node.js on Ubuntu by commands:我正在尝试通过命令在 Ubuntu 上更新 Node.js:

sudo npm install -g n
sudo n latest

I got response:我得到了回应:

installed : v16.6.1 (with npm 7.20.3)

But when I'm checking the version by node -v or nodejs -v I'm getting:但是当我通过node -vnodejs -v检查版本时,我得到:

v10.19.0

Is it required to manually change the system paths?是否需要手动更改系统路径? Old version is not replaced?旧版本不更换?

the reason is that the path for the new node is not included in $PATH .原因是新node的路径未包含在$PATH

you can check that by running which node , it will print the path to node cli.您可以通过运行which node来检查它是否会打印node cli 的路径。

you can fix it by including the path which n install node to the system PATH您可以通过包括路径修复其n安装节点系统PATH

I had the same problem with my Ubuntu 21.10, and I was able to fix it and get the correct version of nodejs to show in my terminal.我的 Ubuntu 21.10 遇到了同样的问题,我能够修复它并获得正确版本的 nodejs 以显示在我的终端中。

The solution is to Set 16.6.1 (or another version) as default解决办法是设置16.6.1(或其他版本)为默认

 nvm alias default 16.6.1

Try this试试这个

$ sudo npm cache clean -f
$ sudo npm install -g n
$ sudo n stable

Upgrade to the latest version, you can use升级到最新版本,即可使用

$ sudo n latest

Fix PATH:修复路径:

$ sudo apt-get install --reinstall nodejs-legacy     

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM