Avatar of Andrea Edwards
Andrea Edwards
 asked on

What is npm install -g npm

Hello

I am learning node and the node package manager. I understand the npm is to install libraries and packages etc. I understand node.js runtime is what will execute the javascript code but in the tutorial I am following it says to do this

npm install -g npm

This is installing the npm package according to the guide. What is the npm package?

Ive read these pages:
https://www.npmjs.com/
https://www.npmjs.com/package/npm

The first page gives common packages which people install, one of which is npm, a javascript package manager

I thought i had already installed the node package manager with node? Please can you explain the difference between the npm command line tool and the npm package you install with it?

Many thanks
Node.jsJavaScript

Avatar of undefined
Last Comment
it_saige

8/22/2022 - Mon
David Favor

Decoding...

npm install -g npm

Open in new window


1) npm - script your running

2) install -g - says to install any packages globally, so anyone can use these packages + only root will be able to update these packages

3) package(s) - in your case you're installing the npm package

So this is likely a local npm installation used to install npm globally.

For this to work you'd have to likely add a sudo, like this...

sudo npm install -g npm

Open in new window


Normally the actual npm command is installed globally in a slightly different manner.

https://github.com/nodesource/distributions provides install instructions for both NodeJS + npm for various Distros.

Best to follow these instructions to install latest NodeJS + npm.
it_saige

If you are installing on a Windows machine, you do not need to use sudo, but you may have to launch an Administrative command prompt.

-saige-
Andrea Edwards

ASKER
Thank you for your detailed reply but I am still confused.

1) Is npm 2 things: both a package manager and a separate package you can install with the package manager too which would be very confusing

2)  Or is npm a package manager which you install 'somehow' then use that to install other packages? Is that general idea correct?

3) If 2) is correct  I can understand that the command I posted is some weird way of using a local install of npm to install it globally. Is that what you are saying (only you didnt say it was weird)?

4) if 2) and 3) are correct and I am on a windows machine, this is the way to install it https://github.com/nodesource/distributions?

Thanks
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
it_saige

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Andrea Edwards

ASKER
Thank you for your answer. It is very clear and you are right it is not weird for something to update itself. Also, thank-you for addressing the questions individually as this greatly facilitates a dialogue.
Andrea Edwards

ASKER
Thank you for your clear explanation
it_saige

Glad I could be of assistance.

-saige-
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.