Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
a safe way to upgrade all of your globally-installed npm packages
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3)
npm -g install "$package"
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f2)
npm -g install "$package"
Copy link

xgvargas commented Mar 30, 2017

I love npm-check too, but my poor man hardware with low memory hates it. So I have developed a very simple package to list outdated packages, install selected ones and update my package.json rules. It will not check for unused or missing packages like npm-check does. But will work with global packages too, and my machine likes it... If you want to take a look: atualiza.

Copy link

callemo commented Apr 21, 2017

This one-liner made the trick for me: npm -gp outdated | cut -d: -f4 | xargs -n1 npm -g install

Copy link

Noyabronok commented May 8, 2017

the one liner updated npm for me :(

Copy link

hrushikesh09 commented Jun 25, 2017

+1 @dylan
npm -g i npm-check

Copy link

calpa commented Aug 6, 2017

+1 @dylang npm-check

Copy link

jan-hudec commented Aug 14, 2017

npm outdated -g seems to have stopped working too. Does not print anything at all here though there definitely are outdated packages.

Copy link

Jeff-Lewis commented Dec 9, 2018

npm outdated -g was fixed a while back and works with npm version 6.4.1.

Copy link

akaleeroy commented Feb 21, 2019

Running npm v6.8.0 and seeing this problem again. Global packages won't update beyond "wanted".

> npm outdated --global
Package        Current  Wanted  Latest  Location
color-convert    1.9.3   1.9.3   2.0.0
mocha            5.2.0   5.2.0   6.0.0
pdfkit           0.8.3   0.8.3   0.9.0

> npm update --global pdfkit
# does nothing

> npm update --global pdfkit@latest
# does nothing

> npm install --global pdfkit
+ pdfkit@0.9.0
added 8 packages from 41 contributors and updated 22 packages in 9.638s

Copy link

KlausEverWalkingDev commented Dec 12, 2020

If you prefer to choose which global modules are updated I've added interactive updating to npm-check with support for global.

It also includes links to the source for each updated package so you can find out what's new.

Behind the scenes npm-check uses npm install thanks to the recommendation from @othiym23 in this thread.

# install
npm -g i npm-check

# interactive update of global packages
npm-check -u -g

# interactive update for a project you are working on
npm-check -u

Example using npm-check -u:
screen shot 2014-10-20 at 10 39 29 am


Great, bro! Thanks! :D

Copy link

martin-braun commented Nov 11, 2022

The Wanted version shall be another major version, which is not very favorable, since it can break things.

Here is a way to upgrade only minor versions of global packages:

npm_global_packages=($(npm list -g --depth 0 | awk '/ /{print $2}'))
for val in "${npm_global_packages[@]}"; do
    npm i -g --force $(echo $val | tr "." "\n" | head -1)

more context

Good part is, that it will not bump npm to a version that is incompatible with the current node version, so this will most likely not break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment