我已经看到了使用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安装…

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

似乎没有人提到这一点。在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 

对于那些想要在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
  # ...

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