ubuntu 20.04上安装更新的nodejs

How To Install Node.js on Ubuntu 20.04 | DigitalOcean

ubuntu20上默认用apt install 安装的nodejs版本是 v10.几

官方提供了对应的脚本, 下面的setup_19.x  如果你需要v18,就把19改成18.

# node 安装较新的版本
curl -sL https://deb.nodesource.com/setup_19.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
# The PPA will be added to your configuration and your local package cache will be updated automatically. 
# You can now install the Node.js package in the same way you did in the previous section:
sudo apt install nodejs
node -v

还有一种方法是使用node version manger,  nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
source ~/.bashrc
nvm list-remote

Output
. . .
        v18.0.0
        v18.1.0
        v18.2.0
        v18.3.0
        v18.4.0
        v18.5.0
        v18.6.0
        v18.7.0
        v18.8.0
        v18.9.0
        v18.9.1
       v18.10.0
       v18.11.0
       v18.12.0   (LTS: Hydrogen)
       v18.12.1   (LTS: Hydrogen)
       v18.13.0   (Latest LTS: Hydrogen)
        v19.0.0
        v19.0.1
        v19.1.0
        v19.2.0
        v19.3.0
        v19.4.0

nvm install v14.10.0

卸载nodejs

sudo apt remove nodejs

nvm uninstall node_version

你可能感兴趣的:(ubuntu,linux,运维)