node.jsamazon-web-servicesnpmyumamazon-linux

How to yum install Node.js on Amazon Linux


I've seen the write-up on using yum to install the dependencies, and then installing Node.js and NPM from source. While this does work, I feel like Node.js and NPM should both be in a public repository somewhere.

How can I install Node.js and NPM in one command on AWS Amazon Linux?


Solution

  • I stumbled onto this, and it was strangely hard to find again later. I am putting it here for posterity:

    sudo yum install nodejs npm --enablerepo=epel
    

    As of July 2016, EDIT 1 no longer works for Node.js 4 (and EDIT 2 neither). This answer (https://stackoverflow.com/a/35165401/78935) gives a true one-liner.

    EDIT 1: If you're looking for Node.js 4, please try the EPEL testing repository:

    sudo yum install nodejs --enablerepo=epel-testing
    

    EDIT 2: To upgrade from Node.js 0.12 installed through the EPEL repository using the command above, to Node.js 4 from the EPEL testing repository, please follow these steps:

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

    The newer packages put the node binaries in /usr/bin, instead of /usr/local/bin.

    And some background:

    The option --enablerepo=epel causes yum to search for the packages in the EPEL repository.

    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/