我们能为您提供什么帮助?

搜索我们的指南和教程,或浏览下方分类。

How to Install Node.js on Ubuntu VPS

224 次浏览 Markdown

Method 1 — Install Node.js from Ubuntu Repository

✔️ Easiest method ✔️ Stable ❌ Not always the latest version

bash

sudo apt update && sudo apt upgrade -y

sudo apt install -y nodejs npm

node -v

npm -v

This installs Node.js + npm directly from Ubuntu’s official repo.

 

Method 2 — Install Latest Node.js via NodeSource (Recommended)

 

This is the best method for production VPS because it gives you the latest LTS or current version.

 

Step 1: Install curl

bash

sudo apt install -y curl

Step 2: Add NodeSource repo (example: Node.js 20.x)

bash

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

Step 3: Install Node.js

bash

sudo apt install -y nodejs

Step 4: Verify

bash

node -v

npm -v

 

Method 3 — Install Node.js Using NVM (Node Version Manager)

 

Best for developers who need to switch between Node versions.

 

Step 1: Install NVM

bash

 

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

source ~/.bashrc

Step 2: Install Node.js (LTS)

bash

nvm install --lts

Step 3: Verify

bash

node -v

npm -v

 

这对您有帮助吗?

感谢您的反馈!

仍需帮助?

如果上述内容未能解答您的问题,我们的支持团队全天候为您服务。