在 Linux 上“安装 JS”通常指以下几种情况之一,我按最常见需求给你说明:
如果你是想运行 JS 代码,需要安装 Node.js。
sudo apt update
sudo apt install nodejs npm
验证:
node -v
npm -v
sudo yum install nodejs npm
或(新版):
sudo dnf install nodejs npm
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts
如果你只是写前端 JS:
.js 文件,用 <script> 引入npm init -y
npm install lodash
❌ “Linux 安装 JavaScript”
✅ 实际是安装 Node.js 运行环境
❌ “JS 像 Python 一样直接装”
✅ JS 需要 运行时(Node)或浏览器
我可以直接给你最合适的安装方式。