How to Install Node.js and NPM on Windows and Mac?

How to Install Node.js and NPM on Windows and Mac

Node.js and NPM (Node Package Manager) are crucial tools for modern web development. Whether you’re building a server-side application, creating a real-time chat app, or managing dependencies for your front-end projects, these tools are indispensable. This guide will help you understand what Node.js and NPM are, and walk you through the steps to install them on both Windows and Mac systems.

What’s NPM?

NPM stands for Node Package Manager. It’s a package manager for JavaScript, allowing developers to share and reuse code. With NPM, you can manage dependencies for your project, making it easier to maintain and deploy your applications. It’s also the default package manager for the JavaScript runtime environment Node.js.

What’s NodeJS?

Node.js is an open-source, cross-platform JavaScript runtime environment that allows you to run JavaScript code outside of a web browser. Developed by Ryan Dahl in 2009, Node.js uses the V8 JavaScript engine, originally developed for Google Chrome, to execute code. This makes it perfect for building scalable network applications, such as web servers, APIs, and real-time services.

Prerequisites

Before installing Node.js and NPM, ensure your system meets the following requirements:

  • Windows: Windows 7 or later
  • Mac: macOS 10.10 or later
  • Internet connection: To download Node.js and NPM
  • Administrator rights: To install software on your computer

Installing Node.js and NPM on Windows

1. Download Node.js Installer:

    2. Run the Installer:

    • Open the downloaded .msi file.
    • Follow the prompts in the Node.js Setup Wizard.
    • Accept the license agreement, choose the destination folder, and select the default components.

    3. Install Node.js and NPM:

    • Click the “Install” button.
    • Once the installation is complete, click “Finish.”

    4. Verify Installation:

    • Open the Command Prompt.
    • Type node -v and press Enter to check the Node.js version.
    • Type npm -v and press Enter to check the NPM version.

    Installing Node.js and NPM on Mac

    1. Download Node.js Installer:

    2. Run the Installer:

    • Open the downloaded .pkg file.
    • Follow the instructions in the Node.js installer.
    • Accept the license agreement and choose the installation location.

    3. Install Node.js and NPM:

    • Click the “Install” button.
    • After the installation is complete, click “Close.”

    4. Verify Installation:

    • Open the Terminal.
    • Type node -v and press Enter to check the Node.js version.
    • Type npm -v and press Enter to check the NPM version.

    Set NODE_HOME in Environment Variable

    Setting the NODE_HOME environment variable helps some programs find your Node.js installation.

    On Windows:

    1. Open the Start menu and search for “Environment Variables.”
    2. Click on “Edit the system environment variables.”
    3. In the System Properties window, click “Environment Variables.”
    4. Under “System variables,” click “New.”
    5. Enter NODE_HOME as the variable name and the path to your Node.js installation as the variable value (e.g., C:\Program Files\nodejs).
    6. Click “OK” to save the changes.

    On Mac:

    1. Open the Terminal.
    2. Type nano ~/.bash_profile to open the Bash profile in the nano editor.
    3. Add the following line:
       export NODE_HOME=/usr/local/bin/node
    1. Press Ctrl + X, then Y, and Enter to save and exit.
    2. Type source ~/.bash_profile to apply the changes.

    Installing Node Using “Homebrew”

    Homebrew is a popular package manager for macOS that simplifies the installation of software.

    1. Install Homebrew:

    • Open the Terminal.
    • Paste the following command and press Enter:
      sh /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    2. Install Node.js and NPM:

    • Once Homebrew is installed, type the following command:
      sh brew install node

    3. Verify Installation:

    • Type node -v and npm -v to check the versions of Node.js and NPM.

    Installing Node Using NVM

    NVM (Node Version Manager) allows you to manage multiple versions of Node.js on your system.

    On Windows:

    1. Download and install NVM from the NVM for Windows GitHub repository.
    2. Open the Command Prompt and type:
       nvm install latest
       nvm use latest
    1. Verify the installation with:
       node -v
       npm -v

    On Mac:

    1. Install NVM using the following command in the Terminal:
       curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
    1. Load NVM:
       export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
       [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    1. Install Node.js:
       nvm install node
    1. Verify the installation:
       node -v
       npm -v

    Key Pointers to Consider

    • Choose LTS Version: For most users, it’s recommended to use the Long-Term Support (LTS) version of Node.js as it is more stable.
    • Regular Updates: Keep Node.js and NPM updated to benefit from the latest features, security patches, and performance improvements.
    • Use Version Managers: Tools like NVM make it easier to switch between different Node.js versions, especially useful for testing and development purposes.

    Conclusion

    Installing Node.js and NPM is a straightforward process that sets the foundation for modern web development. Whether you’re on Windows or Mac, following these steps ensures that you have the tools you need to start building scalable and efficient applications. Remember to regularly update your installations and leverage tools like Homebrew and NVM for efficient management. Happy coding!

    About Author

    Kajal is a freelance content writer, professional blogger, and coffee lover. In addition to developing blog content, she maintains niche websites related to Cryptocurrency, NFT Marketplace, and Artificial Intelligence. His posts are always packed with data and real-life examples.