按照以下步骤在 Ubuntu 20.04 中安装 Node.js 18.12.1:
- 更新 apt 软件包索引:
sudo apt update - 安装 Node.js 的依赖包:
sudo apt install -y curl dirmngr apt-transport-https lsb-release ca-certificates - 导入 Node.js 的 GPG 公钥:
curl -sL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add - - 添加 Node.js 的软件包仓库:
echo "deb https://deb.nodesource.com/node_18.x $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/nodesource.list注意:这里添加的是 Node.js 18.x 的软件包仓库,而不是具体的版本号。
- 重新更新 apt 软件包索引:
sudo apt update - 安装 Node.js:
sudo apt install -y nodejs - 验证 Node.js 是否正确安装:
node -v运行上述命令后,如果终端输出了
v18.12.1,则表示 Node.js 18.12.1 已经成功安装。
本文来自投稿,不代表博客主立场,如若转载,请注明出处:https://www.bokezhu.com/2023/05/16/803.html