Table of Contents
What We Will Cover Here
In this tutorial, I will show you how to install NVM and then using NVM how you can install NodeJS. NVM is a node version manager. It’s a tool to install multiple versions of NodeJs into your server. Here I will show you an example that works on Amazon Linux 1 perfectly. Before you begin please check here on how to create an EC2 instance on AWS.
What is NodeJS and NVM
Node.js is an open-source, cross-platform, back-end, JavaScript runtime environment that executes JavaScript code outside a web browser. It was created in 2009 by Ryan Dahl and since then it is one the most popular JavaScript runtime environment.
nvm is a version manager for node.js, designed to be installed per-user, and invoked per-shell. nvm works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: UNIX, macOS, and Windows WSL. One of the important features of NVM is that you can install multiple NodeJS versions on the same machine and switch between them with whatever version you want.
How to Install
Firstly we need to install NVM. To install NVM please run the following commands
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
To verify whether you have successfully installed NVM or not, please run the following command
command -v nvm
It should output “nvm”. If not displaying “nvm” then close your session and reconnect to SSH and run the command again.
After you have installed NVM successfully, its now task is to install a nodejs version. There are two ways to install nodejs using NVM. To install the latest NodeJs version run the following command.
nvm install node
This will install the latest NodeJs at that particular moment.
If you want to install any specific nodeJs version then run the following command
nvm install 18 # give the version number like 8 or 9 etc.
This will install the latest version of NodeJs 10 to your server.
I have created a video as well to give a real-life example. Here is the video of installing Nodejs
Conclusion
NodeJS is getting very popular among the Full Stack Developer community, and it’s important to learn how to install a different version of NodeJS in Amazon Linux. I hope this article with Video will help you to get started. Feel to visit my nodejs-specific blog to explore further.