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

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


当前回答

似乎没有人提到这一点。在Amazon Linux 2上,加载EPEL的官方方式是:

Sudo amazon-linux-extras安装epel

...那么你可以:

Sudo yum安装nodejs  

参见Extras Library (Amazon Linux 2)

其他回答

我通常使用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 

如官方文件所述,简单以下2步-

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

RHEL、CentOS、CloudLinux、Amazon Linux、Fedora:

# As root
curl -fsSL https://rpm.nodesource.com/setup_12.x | bash -

# No root privileges
curl -fsSL https://rpm.nodesource.com/setup_12.x | sudo bash -

sudo yum install -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/

接受的答案给了我节点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“全局”安装的所有包。