You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Ubuntu 22.04对Node.js 20版本的支持性及升级安装方式咨询

Ubuntu 22.04对Node.js 20版本的支持性及升级安装方式咨询

Hey there! Great question—let's break this down clearly for you.

First off: Node.js 20 (the latest LTS release) is fully supported on Ubuntu 22.04. There are no major compatibility red flags here; this combo is widely used by developers for both production and development environments, so you can feel confident running it.

As for installation: Ubuntu 22.04's default software repositories don't include Node.js 20 out of the box, so you'll need to add an official external source (it's totally safe and straightforward, no hoops to jump through). Here are two reliable methods to get it set up:

Method 1: System-wide installation via NodeSource repository

This is the standard approach for a system-wide Node.js setup:

  • First, remove any existing Node.js/npm installations to avoid conflicts:
    sudo apt remove nodejs npm
    sudo apt autoremove
    
  • Import the NodeSource GPG key to verify package authenticity:
    curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/nodesource.gpg
    
  • Add the Node.js 20 repository to your system:
    echo "deb [signed-by=/etc/apt/trusted.gpg.d/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
    
  • Update your package list and install Node.js 20:
    sudo apt update
    sudo apt install nodejs
    
  • Verify the installation worked:
    node --version  # Should output v20.x.x
    npm --version   # Will show the matching npm version for Node 20
    

Method 2: User-specific installation via nvm (Node Version Manager)

If you need to switch between multiple Node.js versions regularly, nvm is perfect. It installs Node.js in your user directory, so no sudo permissions are needed for version management:

  • Install nvm with the official setup script:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    
  • Restart your terminal, or run this command to load nvm immediately:
    source ~/.bashrc  # Use ~/.zshrc if you're using Zsh instead of Bash
    
  • Install Node.js 20 and set it as your default version:
    nvm install 20
    nvm alias default 20
    
  • Verify the setup:
    node --version
    

Both methods are simple and won't require complex troubleshooting. Node.js 20 runs smoothly on Ubuntu 22.04, so you can go ahead with the upgrade without hesitation.

备注:内容来源于stack exchange,提问作者amal

火山引擎 最新活动