先安装 npm :
参考:https://developer.aliyun.com/article/760687
sudo apt install nodejs npm
下载 n 这个用于更新 node 版本的工具:
sudo npm install n -g
通过 n 这个工具下载 nodejs 的最新稳定版本
sudo n stable
输出:
  installing : node-v18.12.1
       mkdir : /usr/local/n/versions/node/18.12.1
       fetch : https://nodejs.org/dist/v18.12.1/node-v18.12.1-linux-x64.tar.xz
     copying : node/18.12.1
   installed : v18.12.1 (with npm 8.19.2)
Note: the node command changed location and the old location may be remembered in your current shell.
         old : /usr/bin/node
         new : /usr/local/bin/node
If "node --version" shows the old version then start a new shell, or reset the location hash with:
hash -r  (for bash, zsh, ash, dash, and ksh)
rehash   (for csh and tcsh)
可以看到当前下载的是 node-v18.12.1版本。
刷新:
hash -r
然后查看版本:
node -v
输出:
v18.12.1
升级成功。