How to yum install Node.JS on Amazon Linux
Solution 1
Stumbled onto this, was strangely hard to find again later. Putting here for posterity:
sudo yum install nodejs npm --enablerepo=epel
EDIT 3: As of July 2016, EDIT 1 no longer works for nodejs 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 nodejs 4, please try the EPEL testing repo:
sudo yum install nodejs --enablerepo=epel-testing
EDIT 2: To upgrade from nodejs 0.12 installed through the EPEL repo using the command above, to nodejs 4 from the EPEL testing repo, 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/
Solution 2
Like others, the accepted answer also gave me an outdated version.
Here is another way to do it that works very well:
$ curl --silent --location https://rpm.nodesource.com/setup_16.x | bash -
$ yum -y install nodejs
You can also replace the 16.x with another version, such as 18.x, 14.x, etc.
You can see all available versions on the NodeSource Github page, and pull from there as well if desired.
Note: you may need to run using sudo
depending on your environment.
Solution 3
The accepted answer gave me node 0.10.36 and npm 1.3.6 which are very out of date. I grabbed the latest linux-x64 tarball from the nodejs downloads page and it wasn't too difficult to install: 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
Now upzip the tar you just downloaded -
tar xzf node.tgz
Run this command and then also add it to your .bashrc
:
export PATH="$PATH:(your install dir)/(node dir)/bin"
(example : export PATH ="$PATH:/home/ec2-user/mydirectory/node/node4.5.0-linux-x64/bin")
And update npm
(only once, don't add to .bashrc
):
npm install -g npm
Note that the -g
there which means global, really means global to that npm instance which is the instance we just installed and is limited to the current user. This will apply to all packages that npm installs 'globally'.
Solution 4
Simple install with NVM...
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
To install a certain version (such as 12.16.3) of Node change the last line to
nvm install 12.16.3
For more information about how to use NVM visit the docs: https://github.com/nvm-sh/nvm
Solution 5
The procedure that worked for me (following these rather old instructions with a few updates):
- check git is installed
git --version
or install it via:
sudo yum install git
- install gcc and openssl:
sudo yum install gcc-c++ make
sudo yum install openssl-devel
- clone the git repo into a directory called
node
(which you can remove later):
git clone https://github.com/nodejs/node.git
- decide which version of node you want at https://github.com/nodejs/node/releases
- go to the node directory just created and install node
cd node
git checkout v6.1.0
- put your desired version after thev
./configure
make
sudo make install
- test that node is installed / working with either
node --version
or simplynode
(exit node viaprocess.exit()
or^C
x 2 or^C
+exit
) - check the npm version:
npm --version
and update if necessary viasudo npm install -g npm
- Optional: remove the
node
directory withrm -r node
Notes:
- The accepted answer didn't work since
sudo yum install nodejs --enablerepo=epel-testing
returns the error:No package nodejs available.
...andsudo yum install nodejs --enablerepo=epel
(ie without-testing
) only gave very old versions. - If you already have an old version of node installed you can remove it with:
sudo npm uninstall npm -g
...since npm can uninstall itself
sudo yum erase nodejs
sudo rm -f /usr/local/bin/node
(sudo yum rm nodejs
in the accepted answer won't work asrm
is not a valid yum command seeyum --help
) - It's possible to clone the node repo via
git clone git://github.com/nodejs/node.git
rather thangit clone https://github.com/nodejs/node.git
but you may get a various errors (see here). - If you already have a
/node
dir from a previous install, remove it before using the git clone command (or there'll be a conflict):
rm -r node
- If you have trouble with any
sudo npm...
command - likesudo: npm: command not found
and/or have permissions issues installing node packages without sudo, editsudo nano /etc/sudoers
and add:/usr/local/bin
to the end of the lineDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
so that it readsDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
Related videos on Youtube
Tim Fulmer
I am a super-senior software / platform engineer looking to get hands on with your toughest technical challenges. At Domuso I scaled a poorly engineered Groovy application by breaking problem areas out into a new event based serverless architecture in Node.JS running on AWS Lambda. At HopSkipDrive I solved a technical challenge with measuring actual miles driven for the CPUC on a very tight deadline, passing a regulatory hurdle some other ride sharing companies could not.
Updated on July 08, 2022Comments
-
Tim Fulmer almost 2 years
I've seen the writeup on using yum to install the dependencies, and then installing Node.JS & NPM from source. While this does work, I feel like Node.JS and NPM should both be in a public repo somewhere.
How can I install Node.JS and NPM in one command on AWS Amazon Linux?
-
iolsmit over 6 years
-
-
Semicolon about 9 yearsThis is definitely the fastest approach I've seen, but a warning may be useful -- the EPEL repository isn't in sync with the current stable node, and you can't use "n" to fix that when it's been installed this way (at least, not without some kind of magic that's beyond me). The tedious git clone / make install approach is the only way I've found to ensure a consistent and current install.
-
voltrevo over 8 yearsI got node 0.10.36 and npm 1.3.6 out of this. These are very out of date.
-
unboundev over 8 years@Semicolon you can get around that by only installing npm, then
sudo npm install -g n
andsudo n v0.12
or whatever other version you like. -
RandomDeduction over 8 yearsIf using AWS linux and this method, do NOT use n. Instead use
nvm
to upgrade to the latest version.n
doesn't upgrade as expected. -
Neta over 8 years@RandomDeduction's comment fixed it for me. Tried
n
before and didn't work.nvm's github page
- for AWS linux (Amazon Linux) usecURL
and then simplynvm install 5.0
(latest as of now). -
Mariusz over 8 yearsThis is actually the best answer, as you get exactly the version you want
-
user115014 over 8 yearsWish I'd read this answer first - this should be the accepted answer because you can choose which version you want to install. -- thank you @voltrevo
-
Masadow over 8 yearsn update as expected, but it does not update the node link properly. You'll have to run the extra command :
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node
-
Zeno Popovici over 8 years@Masadow You shall live 100 years for this kind gesture Sir! Thanks a lot.
-
Tim Fulmer over 8 years@voltrevo thank you for the answer. Yes, there are other ways to install node on Linux. The accepted answer is a one-liner, which happens to plug into the YUM package system for automated and managed updates. The packages in the YUM repos do tend to be a little bit older, and are also a bit better tested with wider deployments. Personally, I recommend leaving the latest and greatest to local development environments, and use something more like the accepted answer for production environments. Cheers!
-
Jon Burgess over 8 yearsThis is what I needed to use on AWS Elastic Beanstalk to get a more recent version than that already installed.
-
eQ19 about 8 yearsWorks just perfect while I need to run
npm install
forpackage.json
, -
user1336321 about 8 yearsfor old centos versions this is the best way to go
-
Dakotah North about 8 yearsI needed to run this with
curl --silent --location https://rpm.nodesource.com/setup_4.x | sudo bash -
-
David Webber about 8 yearsThis is a fantastic answer. It no longer takes me 20 minutes to install Node anymore.
-
goredwards about 8 yearsthis answer didn't work since
sudo yum install nodejs --enablerepo=epel-testing
returns the error: "No package nodejs available." whilesudo yum install nodejs --enablerepo=epel
only gave very old versions... -
Marek Jalovec almost 8 yearsif you run a php application with some npm compiled frontend on elastic beanstalk, you may use this. it's part of my install.config file that made it work -- gist.github.com/marekjalovec/1ccee0c2254e65fc5d82eb35c7da82ae
-
goredwards almost 8 years@Gio plenty of other answers to choose from if this one doesn't please you ;-) ...'in one command' wasn't the most important part of the question IMHO.
-
nackjicholson almost 8 yearsAnother option. I did
sudo yum install nodejs npm --enablerepo=epel
and then I installed github.com/creationix/nvm and used it to install other versions of node. -
Jayant Bhawal almost 8 yearsThis totally works. Takes less time than @goredwards answer too. Tried on an Amazon ECS optimized AMI.
-
seantomburke over 7 yearsThe accepted answer and all of the EDITs 1-3 didn't work for me, but this worked. Thanks!
-
Daron Tancharoen over 7 yearsThis is very useful after I made a mistake with the accept answer. Thank you
-
Jos Faber over 7 yearsError after running node -v now is: 'cannot execute binary file'. Any ideas?
-
voltrevo over 7 years@JosFaber Hmm this might happen if you download node for a different architecture. You probably want the one that ends in
-linux-x64.tar.gz
. -
goredwards over 7 years@talentedandrew the
etc/sudoers
file controls who can run what commands as what users on what machines - but will only run / find / look for commands that are in directories listed on itssecure_path
Node should be installed in/usr/local/bin
and if it's there sudo should find it - see stackoverflow.com/a/31734090/3092596 If sudo doesn't find it, then that path needs to be added to sudo'ssecure_path
- see also: superuser.com/a/927599/404543 -
Stephen Tetreault over 7 yearsneat and compact.
-
Abhinav over 7 yearssimple and awesome
-
Kirkland about 7 yearsThis should be the answer. It's best best by far unless someone is looking to build from source.
-
BusyProgrammer about 7 yearsYou might want to explain te content in that link. A good answer only uses a link as a reference, not the main topic of the answer.
-
sampoh about 7 yearsIf you get permission denied, you'll need to add some sudo.
curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
andsudo yum -y install nodejs
-
JK. almost 7 yearsTwo issues: 1 - you forgot sudo. 2 - this requires two commands, but your text makes it look like one command. The correct answer is:
$ curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
and then$ sudo yum -y install nodejs
. Don't enter the $ sign obviously, thats just your command prompt. -
Argun over 6 yearsif you wanna install Node.js 8.x, shoud execute
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
-
BuffMcBigHuge over 6 yearsI would like to add that you might have to fix your symbolic links after you install using this method:
sudo ln -s /usr/local/bin/node /usr/bin/node sudo ln -s /usr/local/lib/node /usr/lib/node sudo ln -s /usr/local/bin/npm /usr/bin/npm sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
-
PK. over 6 yearshow do i install 6 to install 7 or 8 if i have already use this method to install 6? i tried install adding the 7 nodesource and uninstalling nodejs and npm and reinstalling but it still installs 6.
-
Miao ZhiCheng about 6 yearsvery old node version, not recommended
-
newbreedofgeek about 5 yearsThis will not work if you are using userdata via cloudformation's AWS::EC2::LaunchTemplate.. it wil lwork if you SSH into your EC2 and run it. I'm still stuck on getting it to work via userdata
-
Stretch over 4 yearswell this seems like the best answer!
-
GabrielBB about 4 years@Stretch Not really. It installs Node 6. Too old.
-
Exelian over 3 yearsThanks for your answer! Please be careful piping code retrieved from the internet directly into
bash
, you may expose yourself to exploits doing this. I would suggest downloading the source first and making sure it contains the script you expect. -
IAM_AL_X about 3 yearsBut can I get a global install? I want "node" in /usr/bin, or the like. Everything I have read, (plus some non-definitive experience) suggests "nvm" wants to install node locally, and then modify my personal PATH so that I personally can find it. But for me, a "global" install, when referring to a CLI, means that all users have access to the executable, without a special PATH modification. (Contrast w regards to a lib in node_modules for "nvm/npm", the word "global"can mean "global to one user".) I am not confident that the "nvm" solution allows for system global. Anybody know for sure?
-
X.X over 2 yearsthis worked perfectly on Amazon Linux 1 (not the amazon linux2). The curl setup_12.X method doesn't work since it doesn't update my existing node 10.x to 12.x as desired. But this nvm method works out great.
-
Zahid Hassan Alvi over 2 yearsthis is the best answer actually!
-
Richard Tyler Miles about 2 yearsnote you can use bash rather than
zsh
as bash is preinstalled.