Table of Contents
Table of Contents
Node.js, created by Ryan Dahl in 2009, has changed the way we use JavaScript in web development. It’s an open-source tool that lets you use JavaScript for both the frontend and backend, making it possible to build full web applications with just one programming language.
Node.js is very effective, as it is based on Chrome’s V8 JavaScript engine. It uses an event-driven, non-blocking I/O model, meaning it can handle many tasks at the same time without slowing down. This is perfect for real-time applications like chat apps, online games, and live streaming.
One of the biggest strengths of Node.js is its ability to handle a lot of users at once, making it great for apps that need to scale. It also has a huge library of packages available through npm (Node Package Manager), which helps developers quickly add features to their apps.
In short, Node.js is a powerful tool that makes it easier to build fast and scalable web applications using JavaScript for everything. Let see the other advantages and uses of node.js
When searching for the benefits of utilizing a specific platform, you should take into account a number of things. The total balance of benefits can be changed by factors including the learning curve, development speed, community, and scale.
Node Version Manager (NVM) is a free tool for managing Node.js versions. It’s simple to use and works with any POSIX-compliant shell, such as sh or bash. With NVM, you can easily install and switch between different versions of Node.js for each shell session. This guide will show you how to install NVM and use it to manage and run various versions of Node.js.
If you want to download Node.js for other operating systems like Windows or macOS, visit the official Node.js website.
Node.js updates frequently, making it hard to test applications with different versions. NVM makes this easier by allowing you to quickly switch between Node.js versions. This helps with checking compatibility and updates for various libraries. NVM keeps Node.js versions and their modules in your user directory, so you don’t need to use sudo. It also simplifies the installation and setup process since you don’t have to get Node.js versions directly from your distribution.
Here we will show you 3 distinct methods to install installing Node.js on an Ubuntu.
We’re hoping now you’re using Ubuntu 22.04T. Before you begin, you should have non-root user account with local package index first by typing:
Step 1: Update Local Package Index
First, refresh your local package index by typing:
sudo apt update
Step 2: Install Node.js
Next, install Node.js using the apt package manager:
sudo apt install nodejs -y
Step 3: Verify Node.js Installation
Check that the installation was successful by querying Node.js for its version number:
node -v
Step 4: Install npm (Node.js Package Manager)
The Node.js package manager, npm, should also be installed. To do so, install the npm package:
sudo apt install npm -y
Check that the npm installation was successful by querying npm for its version number:
npm -v
By following these steps, you will have Node.js and npm installed on your Ubuntu 22.04 system, allowing you to install modules and packages to use with Node.js.
Step 1: Download the NodeSource Installation Script
To obtain the installation script for the preferred Node.js version from your home directory, use cu If you have a different version string, substitute it for 18.x.
curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
You can inspect the contents of the downloaded script with your preferred text editor
vi nodesource_setup.sh
Exit your editor and use sudo to run the script if you are confident it is safe to do so:
sudo bash nodesource_setup.sh
This will add the NodeSource PPA to your configuration and update your local package cache automatically.
Now, install the Node.js package using the apt package manager:
sudo apt install nodejs -y
Check that you’ve installed the new version by running:
node -v
The NodeSource node.js package contains both Node.js and npm, so npm should already be installed. Verify npm installation by running:
npm -v
NVM (Node Version Manager) is a bash script that allows you to manage multiple Node.js versions per user. With NVM, you can easily install and uninstall any Node.js version.
Ensure wget is installed on your system.
sudo apt install wget -y
Use wget to download and install NVM on your Linux system:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
After the installation is complete, run the following commands to set up NVM in your current session:
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Check that NVM was properly installed by typing:
nvm --version
run the following command:
nvm list-remote
This command will print a list of all available Node.js versions.
Next is to install the Node.js latest version, to do so;
Alternatively, you can specify a particular version to install, for example:
nvm install 18.10.0
After the installation, print the Node.js to verify:
node -v
Enter the code below,
By following these steps, you will have NVM installed on your system, allowing you to manage multiple Node.js versions easily.
The approach you take will rely on your needs and interests. Adding and deleting different Node.js versions on a per-user basis is made easier with the nvm approach, even though installing the bundled version from the Ubuntu or NodeSource repository is simpler.