node.js 的新版本在 Xenial 上安装后未显示

New version of node.js doesn't show up after installing on Xenial

我似乎安装了高版本的节点,但它没有显示 node -v 命令。

(base) $ sudo n 10.11.0

  installing : node-v10.11.0
       mkdir : /usr/local/n/versions/node/10.11.0
       fetch : https://nodejs.org/dist/v10.11.0/node-v10.11.0-linux-x64.tar.xz
   installed : v10.11.0 (with npm 6.4.1)

(base) $ node -v
v8.0.0

(base) $ ng
You are running version v8.0.0 of Node.js, which is not supported by Angular CLI 8.0+.
The official Node.js version that is supported is 10.9 or greater.

Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.

从问题正文中显示的输出中,我注意到 sudo n 10.11.0 已在 这个 目录中安装了 node 的新版本:/usr/local/n/versions/node/10.11.0.

该路径需要添加到 $PATH 以便 bash 找到它,如下所示:

PATH=/usr/local/n/versions/node/10.11.0/bin/:$PATH

将以下导出语句添加到 ~/.bashrc

export PATH=/usr/local/n/versions/node/10.11.0/bin/:$PATH

需要重新启动终端才能看到修改后的效果~/.bashrc