Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. The latest version node.js yum repository is maintained by its official website. Use this tutorial to add a yum repository and install Latest Nodejs to Amazon Linux systems.
To install the specific Node.js version, Visit our tutorial Install Specific Node.Js Version with NVM.
Step 1 – Configure Yum Repository
First of all, You need to enable the node.js yum repository in your system provided by the Node.js official website. You also need development tools to build native add-ons to be installed on your system.
For Latest Release:-
sudo yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_19.x | sudo -E bash -
For Stable Release:-
sudo yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_18.x | sudo -E bash -
Step 2 – Install Node.js on Amazon Linux 2
After adding a yum repository to your system let’s install the Node.js package. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.
sudo yum install -y nodejs
- Don’t Miss => Yarn Installation ( A Node Modules Manager)
Step 3 – Check Version
After installation checks the installed version of Node.js. You can find more details about the current version on node.js official website.
node -v
v19.2.0
Also, check the version of npm.
npm -v
8.19.3
Step 4 – Create Demo Web Server (Optional)
This is an optional step. If you want to test your node.js install. Let’s create a web server with the “Welcome Node.js” text. Create a file demo_server.js
vim demo_server.js
and add the following content
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Welcome Node.js'); }).listen(3000, "127.0.0.1"); console.log('Server running at http://127.0.0.1:3000/');
Now start the web server using the command.
node --inspect demo_server.js
Debugger listening on ws://127.0.0.1:9229/8136b052-2b35-402e-8c5c-1d15b027a970
For help, see: https://nodejs.org/en/docs/inspector
Server running at http://127.0.0.1:3000/
Therefore the web server has been started on port 3000. Now access http://127.0.0.1:3000/ URL in the browser.
7 Comments
On the official github nodejssource, as well as on aws documentation, says the following:
WARNING: BUILD SYSTEM CURRENTLY BROKEN FOR NODEJS 18+
You need to install nodejs v16
While performing the steps I am getting below erro
[ec2-user@ip-172-31-35-233 ~]$ sudo yum install -y nodejs
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core | 3.7 kB 00:00
Resolving Dependencies
–> Running transaction check
—> Package nodejs.x86_64 2:18.8.0-1nodesource will be installed
–> Processing Dependency: libc.so.6(GLIBC_2.28)(64bit) for package: 2:nodejs-18 .8.0-1nodesource.x86_64
–> Processing Dependency: libm.so.6(GLIBC_2.27)(64bit) for package: 2:nodejs-18 .8.0-1nodesource.x86_64
–> Finished Dependency Resolution
Error: Package: 2:nodejs-18.8.0-1nodesource.x86_64 (nodesource)
Requires: libc.so.6(GLIBC_2.28)(64bit)
Error: Package: 2:nodejs-18.8.0-1nodesource.x86_64 (nodesource)
Requires: libm.so.6(GLIBC_2.27)(64bit)
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest
i have the same problem
Thank you for quick steps! This is very helpful.
Thank you for this article. this really helped me install node on my Amazon linux 2
I’ve just tried this and it shows that the nodesource repository got added to my AWS instance, but it says “No package node.js is available.”
Rahul, you have written the required article. I want to tell you that I was searching for some solution for installing node.js on my amazon virtual machine. Fortunately, you helped me through this article.
Now, I will perform the instructions mentioned here so that I could get my task done. Thank you.
Please keep sharing and writing such small tutorials.