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

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


当前回答

您可以通过重新安装已安装的包到当前版本来更新/安装节点,这可能会使我们在进行更新时避免大量错误。

这是由nvm使用下面的命令完成的。在这里,我已经将我的节点版本更新到8,并将所有可用的包重新安装到v8 !

nvm i v8 --reinstall-packages-from=default

它也可以在AWS Linux实例上工作。

其他回答

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

Sudo amazon-linux-extras安装epel

...那么你可以:

Sudo yum安装nodejs  

参见Extras Library (Amazon Linux 2)

对于那些想要在Ansible中运行接受的答案而不需要进一步搜索的人,我在这里发布了这个任务,以方便和将来的参考。

接受答案推荐:https://stackoverflow.com/a/35165401/78935

Ansible任务等效

tasks:
  - name: Setting up the NodeJS yum repository
    shell: curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
    args:
      warn: no
  # ...

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

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

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

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/