Install npm in a Few Easy Steps | CSS-Tricks

Do you feel you have a good idea of ​​what a package manager is? We’ve definitely covered a lot of stuff to get to know all the terms and concepts of package managers, but I’d say it’s time already Act Something with our newly discovered knowledge. But first, we need to install npm.

To that end, we’ll make sure Node and npm are installed, then make a small sample project to give you real hands-on experience working with npm basics and what it’s like to use npm on the front end of your development workflow.

Guide chapters

  1. Who is this guide for?
  2. What the heck does “npm” mean?
  3. What the heck is the command line?
  4. What the heck is a knot?
  5. What the heck is a package manager?
  6. How the heck do you install npm? (you are here!)
  7. How do you install npm packages?
  8. What the heck are npm commands?
  9. How the heck do you install an existing npm project?

Check if npm is already installed

Before installing npm we must confirm if it is already installed! If you’re not sure if npm is already installed on your system, open the terminal of your choice, whether it’s a Terminal app in macOS, a terminal built into a code editor like VS Code, or another terminal that you can access on the command line.

ready? Start with this command (note that we do not include a file $ The character in these examples):

node -v

This command displays the current version of the node—if it is installed. If the knot is being Installed, the command line will respond with the currently installed node version number:


Your version might be different, of course. Either way, the fact that the version number appears confirms that npm is installed on your system! Let me confirm it The numbers themselves are not important, as long as we get it some issue number.

If npm or Node Not Currently installed, you will see a message along the lines of “Command not found” instead. In the unlikely event that npm is not installed but Node is not installed (or vice versa), it is probably worth uninstalling it before proceeding.

Suppose you Act Need to have npm and Node installed (and if you haven’t, you are welcome to skip the next section), we’ll take the advice of the official NPM directions and do it via a program called nvm.

Install node version manager

Node Version Manager or nvm allows you to install, update and uninstall Node on your system, as well as to manage multiple versions of Node that you can switch between.

Screenshot of the Node Version Manager repository on GitHub which is closely related to how to install npm in terms of installing Node itself.
Node Version Manager repository on GitHub

As you know, the languages ​​on the server side have their own versions, for example, Node 17.1.0, rather than related to browser versions, such as Chrome 96. We will not need any version of Node but the latest, so this will not be necessary for us in For now, though, it might come in handy for you in the future.

I know, it may seem like a lot of extra work to install one program just to install another, but again, this is the recommended path, and doing things the right way from the start makes it so much easier in the long run. I’d rather set you up for success than make things easier for a while at the cost of more complexity later.

Install nvm on Windows

If you’re on Windows, you’ll really have an easier time here. You’ll need nvm for Windows specifically, but fortunately Windows already has an installer that you can simply download and run. The directions are in the NVM for Windows repo at GitHub.

  • Download the latest version of NVM for Windows. It can be installed manually, if you prefer.
  • Open the terminal and run the file nvm list available Command to see a list of Node versions available for download and installation.
  • turn on nvm use , followed by the Node version number you want to use (eg nvm use 16.9.1) to use a specific version. Alternatively, you can use latestAnd lts, or newest Instead of a specific version number, where newest is the latest installed Version.

Once installed, nvm will work the same way on your Windows machine as on any other system.

Install nvm on macOS

To install nvm on macOS, the first step is to download it with this command:

curl -o- | bash

0.39.0 It is the latest version at the time of publication, but it may be worth checking the nvm install readme and get the latest, if different.

Once you paste this command into the device and press Enters, your output terminal will see a bunch of things that don’t really matter. In fact, I’ll let you in with a little secret: Nobody reads things at their stations most of the time. All we care about is that…

  1. It finally ends; And
  2. It does not end with an error message.

If you are prompted to issue a command in the middle of the installation, press q Boot and continue key.

You’ll know it’s finished when the type cursor starts blinking again, indicating that the terminal is waiting for the typed input. You may see this right after the nvm installation is complete:

=> Close and reopen your terminal to start using nvm or run the following to use it now:

Assuming you don’t see any errors at this point, I’d recommend the simpler option of quitting and restarting whatever terminal app you’re using before moving on. It’s a great way to make sure you’re working with a clean slate.

How to install npm via Node

Now that we have nvm installed we are ready to do what we do really I wanted to do in the first place: install npm and Node on our system.

Not a bad idea to confirm that nvm is installed correctly by running nvm -v. If the device shows you the installed version number, you are good to go! If not, remember that you may have to restart your terminal application before the installation can be completely processed.

Now that we have nvm, installing Node is a very short command:

nvm install node

Simple enough, right?

You should see a message along the lines of Downloading and installing node v17.1.0, although the version number may not match, which is a good thing. You will get the latest stable version at runtime. Wait for the command to finish running—again, you’ll know it’s done once you’re back in the default prompt and are able to type more commands.

After that, you’re all done here! This simple command not only installs Node, but also npm. Again, you can check that everything is installed and updated npm -v And node -v. If all is well, you will get the version number.

What then

Well, at this point we have nvm to install and manage Node, Node itself, and npm to handle Node packages. Then in this npm directory we will install some packages in the project!

Leave a Comment