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

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


当前回答

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)"

其他回答

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

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

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

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

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

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

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

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

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

最简单的解决方案是这样的(以root用户执行这些操作)

sudo su root
cd /etc
mkdir node
yum install wget
wget https://nodejs.org/dist/v9.0.0/node-v9.0.0-linux-x64.tar.gz
tar -xvf node-v9.0.0-linux-x64.tar.gz
cd node-v9.0.0-linux-x64/bin
./node -v
ln -s /etc/node-v9.0.0-linux-x64/bin/node node

接受的答案给了我节点0.10.36和npm 1.3.6,这是非常过时的。我从nodejs下载页面获取了最新的linux-x64 tarball,安装起来并不太难:https://nodejs.org/dist/latest/。

# start in a directory where you like to install things for the current user
(For noobs : it downloads node package as node.tgz file in your directlry)
curl (paste the link to the one you want from the downloads page) >node.tgz

现在将刚刚下载的tar文件压缩

tar xzf node.tgz

运行这个命令,然后将它添加到你的.bashrc:

export PATH="$PATH:(your install dir)/(node dir)/bin"

(例如:export PATH ="$PATH:/home/ec2-user/mydirectory/node/node4.5.0-linux-x64/bin")

更新npm(只有一次,不要添加到.bashrc):

npm install -g npm

注意-g的意思是全局的,对npm实例来说是全局的也就是我们刚刚安装的实例它仅限于当前用户。这将适用于npm“全局”安装的所有包。

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