Installing Node.js on Windows, MacOS, and Linux.

Welcome to our comprehensive guide on installing Node.js! If you’re a beginner wanting to start working with server-side JavaScript, this article is for you. We’ll cover how to install the latest version or a specific version of Node.js on different operating systems in a friendly and detailed manner.

Windows

1. Download Node.js:

  • Visit the official Node.js website (nodejs.org).
  • Choose between the LTS (Long Term Support) version for stability or Current for the latest features. For beginners, LTS is usually the best option.
  • Click the download button corresponding to your system (32-bit or 64-bit).

2. Installation:

  • After downloading, run the .msi file.
  • Follow the setup wizard’s instructions. Click “Next” to accept the license terms and choose the installation location.
  • Optionally, you can add Node.js to your Windows PATH for easier terminal access.

3. Verify Installation:

  • Open Command Prompt or PowerShell and type node -v to check the installed Node.js version. For npm, use npm -v.

Tip for Managing Versions: If you need more than one version of Node.js, consider using nvm-windows, a Node.js version manager for Windows.

MacOS

1. Using Homebrew:

  • If you don’t have Homebrew installed yet, install it first with the command:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install Node.js:

  • Use Homebrew to install Node.js with:
    brew install node@20

3. Verification and Version Management:

  • Verify installation with node -v and npm -v in the terminal.
  • For specific or the latest versions, nvm is ideal:
    • Install nvm with:
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
    • Reload your terminal and install the desired version, for example:
      nvm install 20

Tip: nvm allows easy switching between Node.js versions, perfect for projects requiring different versions.

Linux (Ubuntu Example)

1. Add Nodesource Repository:

  • For the latest LTS version:
    curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

2. Install Node.js:

  • After adding the repository, install Node.js:
    sudo apt-get install -y nodejs

3. Verify Installation:

  • Use node -v and npm -v to check the versions.

Version Manager (NVM):

  • For beginners working with multiple versions, install nvm:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
  • After installation, reload your terminal and use nvm install node for the latest version or nvm install 20 for a specific one.

Tip: NVM is excellent for keeping your development environment flexible and tailored to different project needs.

Conclusion

Now you’re ready to start your journey with Node.js, regardless of your operating system. Remember, practice is key to mastering any technology, so don’t hesitate to experiment, install, and uninstall different versions as you learn. If you have more questions or need further assistance, there are plenty of online resources and communities ready to help!

Happy coding!