Install NodeJS Cross-Platform Guide
Node.js, a powerful JavaScript runtime environment, is essential for modern web development. This article provides a comprehensive guide on installing Node.js across different operating systems: Windows, various Linux distributions, and specifically Ubuntu.
Why Node.js?
Before diving into installation, it's worth noting why Node.js is so popular. It allows developers to use JavaScript on the server-side, enabling full-stack JavaScript development. Its non-blocking, event-driven architecture makes it highly efficient for handling concurrent requests, ideal for building scalable network applications.
1. Installation on Windows:
The easiest way to install Node.js on Windows is using the official installer:
- Download: Go to the official Node.js website (https://nodejs.org/) and download the Windows Installer (.msi) for your system architecture (32-bit or 64-bit). It's generally recommended to download the LTS (Long Term Support) version for stability.
- Run the Installer: Double-click the downloaded .msi file to start the installation wizard.
- Follow the Prompts: Accept the license agreement, choose the installation location (the default is usually fine), and ensure that the "Add to PATH" option is checked. This is crucial for accessing Node.js and npm (Node Package Manager) from your command prompt or PowerShell.
- Verify Installation: Open a new command prompt or PowerShell window (important: a new window is required for the PATH changes to take effect) and run the following commands:
node -v
npm -v
These commands should display the installed versions of Node.js and npm, respectively.
2. Installation on Linux (using NodeSource repositories):
For Linux distributions, using the NodeSource repositories is the recommended method. This ensures you have the latest and most stable versions. These instructions are generally applicable to most Debian/Ubuntu-based distros.
Using apt (Debian/Ubuntu):
- Open a terminal.
- Install necessary tools:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
- Import the NodeSource GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
- Add the NodeSource repository: Replace
<VERSION>
with the desired Node.js version (e.g.,18.x
,20.x
). Check the NodeSource website for the latest LTS version.
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_<VERSION>.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
- Update and install Node.js:
sudo apt-get update
sudo apt-get install nodejs
- Verify Installation: Open a terminal and run:
node -v
npm -v
3. Installation on Ubuntu (using nvm - Node Version Manager):
nvm is a great tool for managing multiple Node.js versions on a single system. This is very useful for projects with different Node.js version requirements.
- Open a terminal.
- Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash # Use the latest version from nvm's github page
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash # Use the latest version from nvm's github page
- Close and reopen your terminal or source the nvm script:
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" # This loads nvm bash_completion
- Install a Node.js version:
nvm install --lts # Installs the latest LTS version
nvm install <version> # Installs a specific version (e.g., nvm install 16)
- Use a specific Node.js version:
nvm use <version> # e.g., nvm use 16 or nvm use --lts
- Verify Installation:
node -v
npm -v
Conclusion:
This guide has covered the most common methods for installing Node.js on Windows, Linux, and Ubuntu. Choose the method that best suits your needs. Using the official installers on Windows and NodeSource repositories on Linux is generally recommended for most users. nvm is highly recommended for developers who need to manage multiple Node.js versions. After successfully installing Node.js, you're ready to start building powerful JavaScript applications.
1 Comments
This is good stuff. I have saved this in my bookmarks for future reference
ReplyDelete