Table of Contents
Guide Chapter
Check if npm is installed
Install Node Version Manager
Install nvm on Windows
Install nvm on MacOS
How to install npm through Node
Next steps
Home Web Front-end CSS Tutorial Install npm in a Few Easy Steps

Install npm in a Few Easy Steps

Mar 15, 2025 am 09:15 AM

Install npm in a Few Easy Steps

Have you understood the basic concepts of package manager? It's time to put the knowledge into practice! First, we need to install npm.

This guide will guide you to install Node and npm and create a sample project that will help you master the basics of npm and its application in front-end development.

Guide Chapter

  1. Who is this guide for?
  2. What does "npm" mean?
  3. What is the command line?
  4. What is Node?
  5. What is a package manager?
  6. How to install npm? (Your current location!)
  7. How to install npm package?
  8. What is the npm command?
  9. How to install an existing npm project?

Check if npm is installed

Before installing npm, check if it is installed. Open a terminal (MacOS terminal application, integrated terminal for code editors such as VS Code, or other command line terminal).

Enter the following command (note that the $character is not included in the example):

 <code>node -v</code>
Copy after login

This command displays the current version of Node (if installed). If Node is installed, the command line returns the installed Node version number:

 <code>v16.9.1</code>
Copy after login

Your version may be different, but as long as the version number is displayed, it means npm is installed! The version number itself does not matter.

If npm or Node is not installed, you will see a message like "Command Not Found". If npm is installed but Node is not installed (and vice versa), it is recommended to uninstall first and then continue.

If you need to install npm and Node, we will follow the official NPM guide to install through the nvm program.

Install Node Version Manager

Node Version Manager (nvm) allows you to install, update, and uninstall Node on your system and manage multiple Node versions.

The server-side language has its own version (e.g., Node 17.1.0) and has nothing to do with the browser version (e.g., Chrome 96). We only need the latest version of Node, so nvm is not needed at the moment, but it may be useful in the future.

Installing one program is just to install another, which seems to be redundant, but it is indeed the recommended method, and doing it correctly from the start will make it easier for later operations.

Install nvm on Windows

If you use Windows, the installation process will be easier. You need nvm dedicated to Windows, but luckily, Windows already has the installer, just download and run. For details, please refer to the NVM for Windows repository on GitHub.

  • Download the latest version of NVM for Windows. It can also be installed manually.
  • Open the terminal and run nvm list available command to view the list of Node versions that can be downloaded and installed.
  • Run the nvm use command followed by the Node version number to use (for example nvm use 16.9.1 ) to use a specific version. Alternatively, you can use latest , lts , ​​or newest instead of a specific version number, where newest is the latest installed version.

After installation, nvm works the same way on a Windows machine as other systems.

Install nvm on MacOS

To install nvm on MacOS, the first step is to download it using the following command:

 <code>curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash</code>
Copy after login

0.39.0 is the latest version at the time of release, but you may need to check the nvm installation readme and get the latest version (if different).

After pasting the command to the terminal and pressing Enter , you will see that the terminal outputs a lot of irrelevant information. In fact, most of the time, no one will read this information in the terminal. We only care about:

  1. The order is finally completed; and
  2. The command does not end with an error message.

If you are prompted to enter a command during the installation process, press the q key to exit and continue.

When the input cursor flashes again, it means that the command has been completed and the terminal is waiting for your input. After the nvm installation is complete, you may see:

 <code>=> Close and reopen your terminal to start using nvm or run the following to use it now:</code>
Copy after login

If you do not see an error at this time, it is recommended to exit and restart the terminal application you are using before continuing. This is a great way to ensure you start with a clean condition.

How to install npm through Node

Now that nvm is installed, we are ready to do what we really want to do: install npm and Node on the system.

It is best to confirm that nvm is installed correctly, by running nvm -v . If the terminal displays the installed version number, everything is fine! If not, remember that you may need to restart the terminal application to complete the installation.

Now that we have nvm, the command to install Node is very short:

 <code>nvm install node</code>
Copy after login

Simple enough, right?

You should see a message like "Downloading and installing node v17.1.0", although the version number may not match, that's OK. You will get the latest stable version of the runtime. Wait for the command to finish running – Similarly, when you go back to the default prompt and be able to type more commands, you know it's done.

After that, you're done! This simple command not only installs Node, but also installs npm. Similarly, you can use npm -v and <code>node -v</code> to verify that everything is installed and updated. If all goes well, you will get the version number.

Next steps

OK, now we have nvm for installing and managing Node, Node itself, and npm for handling Node packages. In the next part of this npm guide, we will install some packages into the project!

← Chapter 5 Chapter 7 →

The above is the detailed content of Install npm in a Few Easy Steps. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Google Fonts   Variable Fonts Google Fonts Variable Fonts Apr 09, 2025 am 10:42 AM

I see Google Fonts rolled out a new design (Tweet). Compared to the last big redesign, this feels much more iterative. I can barely tell the difference

How to Create an Animated Countdown Timer With HTML, CSS and JavaScript How to Create an Animated Countdown Timer With HTML, CSS and JavaScript Apr 11, 2025 am 11:29 AM

Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

How to select a child element with the first class name item through CSS? How to select a child element with the first class name item through CSS? Apr 05, 2025 pm 11:24 PM

When the number of elements is not fixed, how to select the first child element of the specified class name through CSS. When processing HTML structure, you often encounter different elements...

HTML Data Attributes Guide HTML Data Attributes Guide Apr 11, 2025 am 11:50 AM

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

A Proof of Concept for Making Sass Faster A Proof of Concept for Making Sass Faster Apr 16, 2025 am 10:38 AM

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

See all articles