EDIT: several years since this question was first answered, as noted in a newer answer, there is now a command for this:
nvm now has a command to update npm. It's nvm install-latest-npm
or nvm install --latest-npm
.
nvm install-latest-npm
: Attempt to upgrade to the latest working npm
on the current node version
nvm install --latest-npm
: After installing, attempt to upgrade to the latest working npm on the given node version
Below are previous revisions of the correct answer to this question.
Over three years after this question was first asked, it seems like the answer is much simpler now. Just update the version that nvm installed, which lives in ~/.nvm/versions/node/[your-version]/lib/node_modules/npm
.
I just installed node 4.2.2, which comes with npm 2.14.7, but I want to use npm 3. So I did:
cd ~/.nvm/versions/node/v4.2.2/lib
npm install npm
Easy!
And yes, this should work for any module, not just npm, that you want to be "global" for a specific version of node.
EDIT 1: In the newest version, npm -g
is smart and installs modules into the path above instead of the system global path.
Thanks @philraj for pointing this out in a comment.
npm list
for local packages or npm list -g
for globally installed packages.
You can find the version of a specific package by passing its name as an argument. For example, npm list grunt
will result in:
projectName@projectVersion /path/to/project/folder
└── grunt@0.4.1
Alternatively, you can just run npm list
without passing a package name as an argument to see the versions of all your packages:
├─┬ cli-color@0.1.6
│ └── es5-ext@0.7.1
├── coffee-script@1.3.3
├── less@1.3.0
├─┬ sentry@0.1.2
│ ├── file@0.2.1
│ └── underscore@1.3.3
└── uglify-js@1.2.6
You can also add --depth=0
argument to list installed packages without their dependencies.
Best Answer
angular cli can report its version when you run it with the version flag