Node.js is a powerful JavaScript runtime built on Chrome’s V8 engine that allows developers to build scalable network applications. Along with Node.js, npm (Node Package Manager) is installed by default, which helps manage libraries and dependencies in your project. This guide will walk you through the process of installing Node.js and npm on different operating systems: Windows, macOS, and Linux.
Installing Node.js and npm on Windows
Step 1: Download Node.js
- Open your browser and go to the official Node.js website.
- On the homepage, you will see two versions of Node.js:
- LTS (Long Term Support): This version is recommended for most users.
- Current: This version includes the latest features but might be less stable.
- Choose the appropriate version for your needs and download the installer (usually a
.msi
file).
Step 2: Run the Installer
- Once the download is complete, open the
.msi
file. - Follow the instructions in the installer. Make sure to:
- Accept the license agreement.
- Choose the destination folder for installation (or leave it as default).
- Keep the option to add Node.js to the PATH environment variable checked.
- Complete the installation process by clicking Next and then Finish.
Step 3: Verify the Installation
To confirm that Node.js and npm have been installed successfully:
- Open the Command Prompt (you can search for it in the Start menu).
- Run the following commands:
node -v
This command should return the installed version of Node.js.
npm -v
This command will return the version of npm that was installed along with Node.js.
Installing Node.js and npm on macOS
Step 1: Install Node.js Using Homebrew (Recommended)
- If you don’t have Homebrew installed, install it by running the following command in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Once Homebrew is installed, you can install Node.js by running:
brew install node
This will install both Node.js and npm.
Step 2: Verify the Installation
Once the installation is complete, you can verify that Node.js and npm are installed correctly:
- Open Terminal.
- Run the following commands:
node -v
npm -v
Both commands should return the installed versions of Node.js and npm.
Alternative Method: Install Node.js from the Official Website
- Go to the Node.js website and download the macOS installer (
.pkg
file). - Run the downloaded
.pkg
file and follow the on-screen instructions to install Node.js. - After installation, verify by running
node -v
andnpm -v
in Terminal.
Installing Node.js and npm on Linux (Ubuntu/Debian-Based Systems)
Step 1: Update the Package Index
Before installing Node.js, make sure your system is up-to-date:
sudo apt update
Step 2: Install Node.js
There are multiple ways to install Node.js on Linux. The recommended method is by using the NodeSource repository to get the latest version.
- To add the NodeSource PPA, run the following commands:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
- Once the PPA is added, install Node.js and npm with this command:
sudo apt-get install -y nodejs
Step 3: Verify the Installation
To confirm Node.js and npm are installed:
node -v
npm -v
This will display the installed versions.
Using Node Version Manager (nvm) to Manage Node.js Versions
For more flexibility, you can use nvm (Node Version Manager), which allows you to easily install and switch between different versions of Node.js.
Step 1: Install nvm
To install nvm, run the following command in your Terminal (works on Linux and macOS):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
Step 2: After the installation, restart your Terminal.
Step 3: Install Node.js with nvm
Once nvm is installed, you can use it to install the latest LTS version of Node.js:
nvm install --lts
You can also list all available versions and install specific ones:
nvm list-remote
nvm install <version>
Step 3: Verify Installation
After installing Node.js using nvm, verify the installation:
node -v
npm -v
Conclusion
Installing Node.js and npm on any operating system is a straightforward process, whether you’re using an installer from the Node.js website, a package manager like Homebrew, or Node Version Manager (nvm). With Node.js set up on your machine, you’re ready to start building scalable applications or experimenting with the vast ecosystem of npm packages.
Whether you’re on Windows, macOS, or Linux, this guide has covered the essential steps to get you up and running with Node.js and npm in no time.
Leave a Reply
You must be logged in to post a comment.