From Start to Finish: The Ultimate Guide to Installing Node and NPM on Your Local Machine

How to install Node JS and NPM locally

Vinojan Veerapathirathasan
7 min readMay 2, 2023
Install Node and npm with Vinojan

Introduction to Node.js and NPM

Node.js is an open-source, cross-platform, JavaScript runtime environment that allows developers to run JavaScript code outside of a web browser. Node.js was created in 2009 by Ryan Dahl and has since become a popular choice for building web applications and command-line tools.

One of the key features of Node.js is its ability to use packages and modules that are available through the Node Package Manager (NPM). NPM is the default package manager for Node.js and is used to install and manage packages that provide additional functionality to your Node.js applications.

NPM makes it easy to install and manage packages from the NPM registry, which contains over 1 million packages created by developers from around the world. These packages can be used to add functionality to your application, such as database connectivity, image processing, or even full-stack web development frameworks.

Understanding the Installation Process

Before we dive into the specifics of how to install Node.js and NPM on various operating systems, it’s helpful to understand the installation process and what’s happening behind the scenes.

When you install Node.js, you’re essentially installing a program that allows you to run JavaScript code outside of a web browser. The installation process involves downloading and installing the Node.js runtime, which includes the V8 JavaScript engine (the same engine used in Google Chrome), as well as various libraries and dependencies that Node.js needs to run.

NPM, on the other hand, is installed as part of the Node.js installation process. When you install Node.js, NPM is included as a package that allows you to easily install and manage packages for your Node.js projects.

Once you have Node.js and NPM installed, you can start using NPM to install packages for your Node.js projects. When you install a package using NPM, it downloads the package from the NPM registry and installs it in a node_modules directory in your project's directory. NPM also creates a package.json file in your project's directory, which contains information about your project and its dependencies.

In the following sections, we’ll go through the steps for installing Node.js and NPM on Windows, macOS, and Linux, and show you how to verify that they’re installed correctly.

Installing Node.js and NPM on Windows

Installing Node.js and NPM on Windows is a straightforward process.

  1. First we need to download the Windows installer for the LTS (Long-term Support) version of Node.js from the official website(https://nodejs.org/en/). The LTS version is recommended for most users, as it provides a stable and supported version of Node.js.
  2. Once the installer is downloaded, we can run it and follow the prompts to install Node.js. During the installation process, we can choose the installation directory and select any additional features we may need. The default installation settings should be fine for most users.
  3. After the installation is complete, we need to add the Node.js and NPM directories to our system environment variables. This will allow us to run Node.js and NPM from the command line.
    To do this, we need to open the System Properties window, click on the Advanced tab, and then click on the Environment Variables button. From here, we can add the Node.js and NPM directories to the PATH variable.
  4. To verify that Node.js and NPM are installed correctly, open a command prompt or PowerShell window and run the following commands:
node -v
npm -v

These commands should return the version numbers of Node.js and NPM, respectively.

Installing Node.js and NPM on Mac

Installing Node.js and NPM on a Mac is also a straightforward process.

  1. First we need to download the macOS installer for the LTS (Long-term Support) version of Node.js from the official website(https://nodejs.org/en/). The LTS version is recommended for most users, as it provides a stable and supported version of Node.js.
  2. Once the installer is downloaded, we can run it and follow the prompts to install Node.js. The default installation settings should be fine for most users.
  3. After the installation is complete, we need to verify that Node.js and NPM are installed correctly by opening a terminal window and running the following commands:
node -v
npm -v

Installing Node.js and NPM on Linux

Installing Node.js and NPM on Linux is a bit more involved than on Windows or Mac, as there are many different Linux distributions and installation methods. However, the official Node.js website provides detailed instructions for installing Node.js and NPM on various Linux distributions.

Using Terminal

To install Node.js and NPM using Terminal, the steps vary depending on the Linux distribution you are using. Here, we’ll cover the general steps that should work for most distributions.

  1. First, open a terminal window and update your package manager’s cache by running the following command:
sudo apt update

This will ensure that you have the latest package information before you install Node.js.

2. Next, install Node.js and NPM by running the following command:

sudo apt install nodejs npm

This will install the LTS (Long-term Support) version of Node.js and NPM from the default package repository for your distribution.

3. Once the installation is complete, verify that Node.js and NPM are installed correctly by running the following command:

node -v
npm -v

Using Snap

Packages compatible with Debian and Ubuntu based Linux distributions are available via Node.js snaps.

Using NVM

You can try installing Node.js and NPM using a package manager called nvm (Node Version Manager).

Let’s checkout this article to install using NVM, It will provides you the full guidance of installation nodejs and npm with NVM.
https://medium.com/@iam_vinojan/how-to-install-node-js-and-npm-using-node-version-manager-nvm-143165b16ce1

Troubleshooting Common Installation Errors

Even if you follow the installation steps correctly, you may still encounter errors during the installation process. Here are some common errors and their solutions:

  1. Node.js and/or NPM is not recognized as an internal or external command
    If you see this error message after installing Node.js and NPM, it may be because they were not added to your system’s PATH environment variable. To fix this, you can add the Node.js and NPM directories to your PATH variable manually. The directories can usually be found in the following locations:
    - Windows: C:\Program Files\nodejs\
    - macOS and Linux: /usr/local/bin/
  2. Error: EACCES: permission denied, access…
    If you see this error message when running an NPM command, it may be because you don’t have the necessary permissions to write to a certain directory. To fix this, you can try running the command with elevated privileges using the sudo command (e.g., sudo npm install -g package_name).
  3. Error: ENOENT: no such file or directory…
    If you see this error message when running an NPM command, it may be because the package you’re trying to install doesn’t exist in the NPM registry. Double-check the package name and try again.
  4. Error: SSL certificate problem: unable to get local issuer certificate
    If you see this error message when running an NPM command, it may be because your system’s SSL certificate is not configured correctly. To fix this, you can try updating your system’s SSL certificate bundle or disable SSL verification using the -insecure flag with your NPM command (e.g., npm install -insecure package_name).

If you encounter any other errors during the installation process, try searching online for solutions or consulting the documentation for your specific operating system and package manager.

How to Update Node.js and NPM

Node.js and NPM are constantly evolving, with new features and bug fixes being added in each version release. It’s important to keep your Node.js and NPM installations up to date to take advantage of these improvements. Here’s how you can update Node.js and NPM to the latest versions:

  • Updating Node.js
    To update Node.js, you can use a package manager like NPM. First, open a terminal window and run the following command to update NPM to the latest version:
npm install -g npm@latest
  • Updating NPM
    If you want to update NPM independently of Node.js, you can run the following command:
npm install -g npm@latest

Best Practices for Managing Node.js and NPM Versions

Managing Node.js and NPM versions can be challenging, especially when working on multiple projects that require different versions. One best practice is to use a version manager like NVM, as mentioned earlier. This allows us to easily switch between different versions of Node.js and NPM without affecting other projects.

Another best practice is to specify the required versions of Node.js and NPM in our project’s package.json file. This ensures that everyone working on the project is using the same versions of Node.js and NPM, which can prevent compatibility issues and make it easier to maintain the project in the long run.

Conclusion

In conclusion, installing and managing Node.js and NPM is an essential part of web development. By following the steps outlined in this guide, you can install Node.js and NPM on your local machine and start building powerful web applications. Remember to keep your versions up to date, use a version manager, and specify your project’s dependencies in the package.json file.

If you are interested in learning more about web development and other tech-related topics, feel free to visit my profile to read more articles and tech-related news.

Thank you for taking the time to read this article. I hope that it has provided you with the information and guidance you needed. If you have found this article helpful, please feel free to share it. I would also like to thank you for your continued support and look forward to being of further assistance in the future. If you have any questions or feedback, please do not hesitate to reach out. Thank you again for your time and consideration.

✍️ By
Vinojan Veerapathirathasan
Founder and CEO at DecHorizon Technologies
LinkedIn : https://www.linkedin.com/in/iam-vinojan/
hello@vinojan.online | +94 75 372 7782

--

--

Vinojan Veerapathirathasan

Software Engineer at EL | Designer | Medium Writer | AI Enthusiast | Entrepreneur | Specializing in Modern Web Application Development