sudo apt update
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
sudo yum install -y gcc-c++ make
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm use --lts
which node
或 whereis node
查看安装路径(通常为 /usr/local/bin
)。~/.bashrc
/~/.zshrc
,添加以下内容(替换为实际路径):export PATH=$PATH:/usr/local/bin
source ~/.bashrc
运行以下命令检查版本:
node -v # 显示Node.js版本
npm -v # 显示npm版本
npm install -g npm
nodemon
等工具,执行:npm install -g nodemon
mkdir my-node-app && cd my-node-app
npm init -y
app.js
,内容示例:const http = require('http');
http.createServer((req, res) => {
res.end('Hello Node.js!');
}).listen(3000, () => console.log('Server running on http://localhost:3000'));
node app.js