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

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


当前回答

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

教程:在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)"

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

其他回答

EC2-Instance的官方文档:https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html

 1. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
 2. . ~/.nvm/nvm.sh
 3. nvm ls-remote (=> find your version x.x.x =>) nvm install  x.x.x
 4. node -e "console.log('Running Node.js ' + process.version)"

sudo yum install nodejs npm——enablerepo=epel适用于Amazon Linux AMI。 Curl—silent—location https://rpm.nodesource.com/setup_6.x | bash - Yum -y安装nodejs 在红帽公司工作。

偶然发现了这个,奇怪的是后来很难再找到了。为子孙后代写在这里:

sudo yum install nodejs npm --enablerepo=epel

EDIT 3:截至2016年7月,EDIT 1不再适用于nodejs 4 (EDIT 2也一样)。这个答案(https://stackoverflow.com/a/35165401/78935)给出了一个真正的单行程序。

编辑1:如果你正在寻找nodejs 4,请尝试EPEL测试repo:

sudo yum install nodejs --enablerepo=epel-testing

编辑2:使用上面的命令从EPEL repo安装的nodejs 0.12升级到EPEL测试repo的nodejs 4,请遵循以下步骤:

sudo yum rm nodejs
sudo rm -f /usr/local/bin/node
sudo yum install nodejs --enablerepo=epel-testing

较新的包将节点二进制文件放在/usr/bin中,而不是/usr/local/bin。

一些背景知识:

选项——enablerepo=epel会导致yum在epel存储库中搜索包。

EPEL (Extra Packages for Enterprise Linux) is open source and free community based repository project from Fedora team which provides 100% high quality add-on software packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux. Epel project is not a part of RHEL/Cent OS but it is designed for major Linux distributions by providing lots of open source packages like networking, sys admin, programming, monitoring and so on. Most of the epel packages are maintained by Fedora repo. Via http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/

和其他人一样,这个公认的答案也给了我一个过时的版本。

这里有另一种非常有效的方法:

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

您也可以替换16。X与另一个版本,如18。x, 14。x,等等。

您可以在NodeSource Github页面上看到所有可用的版本,如果需要,也可以从那里提取。

注意:根据您的环境,您可能需要使用sudo运行。

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

教程:在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)"

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