我已经看到了使用yum安装依赖项,然后从源代码安装Node.JS和NPM的文章。虽然这是可行的,但我觉得Node.JS和NPM都应该在公共回购的某个地方。

如何在AWS亚马逊Linux上一个命令安装Node.JS和NPM ?


当前回答

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Curl—silent—location https://rpm.nodesource.com/setup_10.x | sudo bash - Sudo yum -y安装nodejs

其他回答

我偶然发现了这个。我尝试了一些比较流行的答案,但最后对我有用的是亚马逊的快速设置指南。

教程:在Amazon EC2实例上设置Node.js

本教程的要点是:

确保已通过ssh连接到实例。 获取nvm: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash 活跃。~ / .nvm / nvm.sh 使用nvm Install 4.4.5安装节点(注意:您可以选择不同的版本。首先运行$ nvm ls-remote检查远程版本) 最后,运行$ node -e "console.log(' running node .js' + process.version)"

希望这能帮助到下一个人。

我通常使用NVM在服务器上安装节点。它让我可以选择安装多个版本的nodejs。

命令如下:

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

然后检查是否正确安装:

command -v nvm

在那之后,运行这个来安装最新版本:

nvm install node 

or

nvm install 11 

简单的NVM安装…

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

如果要安装某个版本的Node(如18.12.1),请将最后一行更改为

nvm install 18.12.1

有关如何使用NVM的更多信息,请访问文档: https://github.com/nvm-sh/nvm

对于v4 LTS版本使用:

curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum -y install nodejs

对于Node.js v6的使用:

curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs

在尝试在Amazon Linux上安装本机插件时,我也遇到了一些问题。如果你想这样做,你也应该安装构建工具:

yum install gcc-c++ make

正如亚马逊文档(在亚马逊EC2实例上设置Node.js)中所述,只需运行以下命令:

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

完成了!