Link to home
Create AccountLog in
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
Avatar of David Favor
David Favor
Flag of United States of America image

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.
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-
Avatar of Andrea Edwards
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
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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.
Thank you for your clear explanation
Glad I could be of assistance.

-saige-