Create a gist now

Instantly share code, notes, and snippets.

Embed
a safe way to upgrade all of your globally-installed npm packages
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3)
do
npm -g install "$package"
done
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f2)
do
npm -g install "$package"
done
@othiym23

This comment has been minimized.

Show comment
Hide comment
@othiym23

othiym23 Sep 20, 2014

Use npm-upgrade.sh most of the time; use npm-upgrade-bleeding.sh if you have packages that are newer than <package>@latest and you want to keep them on the absolute newest version rather than latest.

Owner

othiym23 commented Sep 20, 2014

Use npm-upgrade.sh most of the time; use npm-upgrade-bleeding.sh if you have packages that are newer than <package>@latest and you want to keep them on the absolute newest version rather than latest.

@aredridel

This comment has been minimized.

Show comment
Hide comment
@aredridel

aredridel Sep 20, 2014

What makes this safer?

What makes this safer?

@pgilad

This comment has been minimized.

Show comment
Hide comment
@pgilad

pgilad Sep 20, 2014

npm update -g also upgrades recursively all npm global dependencies

pgilad commented Sep 20, 2014

npm update -g also upgrades recursively all npm global dependencies

@makenova

This comment has been minimized.

Show comment
Hide comment
@makenova

makenova Sep 21, 2014

Thanks, I threw this in my ~/bin dir.
Is it possible to make the unmet dependency warnings go away?

Thanks, I threw this in my ~/bin dir.
Is it possible to make the unmet dependency warnings go away?

@othiym23

This comment has been minimized.

Show comment
Hide comment
@othiym23

othiym23 Sep 21, 2014

@makenova that's due to a change in semver in npm 2 that will gradually work itself out as deps get upgraded. So yes, but not right away.

Owner

othiym23 commented Sep 21, 2014

@makenova that's due to a change in semver in npm 2 that will gradually work itself out as deps get upgraded. So yes, but not right away.

@othiym23

This comment has been minimized.

Show comment
Hide comment
@othiym23

othiym23 Sep 21, 2014

@aredridel see npm/npm#6247 for details on why this is better.

Owner

othiym23 commented Sep 21, 2014

@aredridel see npm/npm#6247 for details on why this is better.

@makenova

This comment has been minimized.

Show comment
Hide comment
@makenova

makenova Sep 21, 2014

Actually this broke my npm install.
It tried to install npm@2.0.0, had an error, tried to roll back but failed.

Actually this broke my npm install.
It tried to install npm@2.0.0, had an error, tried to roll back but failed.

@makenova

This comment has been minimized.

Show comment
Hide comment
@makenova

makenova Sep 21, 2014

@othiym23, I did a manual install to fix it. Thanks for the script!!

@othiym23, I did a manual install to fix it. Thanks for the script!!

@jasonkarns

This comment has been minimized.

Show comment
Hide comment
@jasonkarns

jasonkarns Sep 22, 2014

Suggestion: #!/usr/bin/env sh for portability.

Suggestion: #!/usr/bin/env sh for portability.

@mmocny

This comment has been minimized.

Show comment
Hide comment
@mmocny

mmocny Sep 22, 2014

Old issue for adding npm upgrade command: npm/npm#4471

Long standing call-for-PR...

mmocny commented Sep 22, 2014

Old issue for adding npm upgrade command: npm/npm#4471

Long standing call-for-PR...

@othiym23

This comment has been minimized.

Show comment
Hide comment
@othiym23

othiym23 Sep 22, 2014

@jsonkarns: if you don't have /bin/sh, you don't have UNIX.

Owner

othiym23 commented Sep 22, 2014

@jsonkarns: if you don't have /bin/sh, you don't have UNIX.

@mAAdhaTTah

This comment has been minimized.

Show comment
Hide comment
@mAAdhaTTah

mAAdhaTTah Sep 25, 2014

You can run this if you don't feel like downloading it : source <(curl -fsSL https://gist.githubusercontent.com/othiym23/4ac31155da23962afd0e/raw/4ead4c8989c66104a22240819131b99295bc4e37/npm-upgrade.sh)

Add the -bleeding to the url if you like to live on the edge.

You can run this if you don't feel like downloading it : source <(curl -fsSL https://gist.githubusercontent.com/othiym23/4ac31155da23962afd0e/raw/4ead4c8989c66104a22240819131b99295bc4e37/npm-upgrade.sh)

Add the -bleeding to the url if you like to live on the edge.

@dylang

This comment has been minimized.

Show comment
Hide comment
@dylang

dylang Oct 20, 2014

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

Source: https://github.com/dylang/npm-check

dylang commented Oct 20, 2014

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

Source: https://github.com/dylang/npm-check

@iki

This comment has been minimized.

Show comment
Hide comment
@iki

iki Nov 6, 2014

Batch script for Windows is available in gist fork
https://gist.github.com/iki/ec32bfdeeb23930efd15 (cc @othiym23)

iki commented Nov 6, 2014

Batch script for Windows is available in gist fork
https://gist.github.com/iki/ec32bfdeeb23930efd15 (cc @othiym23)

@iki

This comment has been minimized.

Show comment
Hide comment
@iki

iki Nov 10, 2014

@othiym23: I needed to add -q to npm options to reset the loglevel to warn, so that http level msgs are not in the output ... this is generally good practice, as different people can have different default loglevel set in their .npmrc

iki commented Nov 10, 2014

@othiym23: I needed to add -q to npm options to reset the loglevel to warn, so that http level msgs are not in the output ... this is generally good practice, as different people can have different default loglevel set in their .npmrc

@sonarxavier

This comment has been minimized.

Show comment
Hide comment
@sonarxavier

sonarxavier Jan 29, 2015

Thanks for the npm-check util update!

Thanks for the npm-check util update!

@curtisalexander

This comment has been minimized.

Show comment
Hide comment
@curtisalexander

curtisalexander Feb 28, 2015

This caused me a lot of heartburn...hope it helps others who find the thread.

The --parseable flag changes the order of the output from npm outdated without the flag.

npm outdated -g --depth=0 produces output according to the header → current | wanted | latest
npm outdated -g --depth=0 --parseable produces output in a different order → wanted | current | latest

# current
npm outdated <package> -g --depth=0 --parseable | cut -d: -f3

# wanted 
npm outdated <package> -g --depth=0 --parseable | cut -d: -f2

# latest
npm outdated <package> -g --depth=0 --parseable | cut -d: -f4

This caused me a lot of heartburn...hope it helps others who find the thread.

The --parseable flag changes the order of the output from npm outdated without the flag.

npm outdated -g --depth=0 produces output according to the header → current | wanted | latest
npm outdated -g --depth=0 --parseable produces output in a different order → wanted | current | latest

# current
npm outdated <package> -g --depth=0 --parseable | cut -d: -f3

# wanted 
npm outdated <package> -g --depth=0 --parseable | cut -d: -f2

# latest
npm outdated <package> -g --depth=0 --parseable | cut -d: -f4
@jasonkarns

This comment has been minimized.

Show comment
Hide comment
@jasonkarns

jasonkarns Mar 24, 2015

@jsonkarns: if you don't have /bin/sh, you don't have UNIX.

@othiym23 I don't follow. The env isn't to guard against not having sh. It's to ensure that these scripts run against the user's preferred sh executable. For example, running against a homebrew-built sh instead of old system install. Since these scripts are intended to be used directly by the user (and not automated or as part of a utility), then they should be run against the user's chosen executable.

@jsonkarns: if you don't have /bin/sh, you don't have UNIX.

@othiym23 I don't follow. The env isn't to guard against not having sh. It's to ensure that these scripts run against the user's preferred sh executable. For example, running against a homebrew-built sh instead of old system install. Since these scripts are intended to be used directly by the user (and not automated or as part of a utility), then they should be run against the user's chosen executable.

@steventhomson

This comment has been minimized.

Show comment
Hide comment
@steventhomson

steventhomson Sep 16, 2015

FYI: npm @2.6.1+ does not recursively update dependencies by default anymore.
https://docs.npmjs.com/cli/update

FYI: npm @2.6.1+ does not recursively update dependencies by default anymore.
https://docs.npmjs.com/cli/update

@leomperes

This comment has been minimized.

Show comment
Hide comment
@leomperes

leomperes May 5, 2016

+1 @dylang , thanks bro!!!

+1 @dylang , thanks bro!!!

@martisj

This comment has been minimized.

Show comment
Hide comment
@martisj

martisj Sep 18, 2016

+1 @dylang npm-check for president!

martisj commented Sep 18, 2016

+1 @dylang npm-check for president!

@edoardoc

This comment has been minimized.

Show comment
Hide comment
@edoardoc

edoardoc Jan 9, 2017

+1 @dylang npm-check

edoardoc commented Jan 9, 2017

+1 @dylang npm-check

@finalbytes

This comment has been minimized.

Show comment
Hide comment
@finalbytes

finalbytes Jan 24, 2017

+1 @dylang npm-check

+1 @dylang npm-check

@agalazis

This comment has been minimized.

Show comment
Hide comment
@agalazis

agalazis Jan 29, 2017

+1 for npm-check

+1 for npm-check

@hoanganh25991

This comment has been minimized.

Show comment
Hide comment
@hoanganh25991

hoanganh25991 Feb 3, 2017

+1 for npm-check
should have emotion for answer in gist, which easy to rise a thumbsub on @dylang's anwser

hoanganh25991 commented Feb 3, 2017

+1 for npm-check
should have emotion for answer in gist, which easy to rise a thumbsub on @dylang's anwser

@GBarkhatov

This comment has been minimized.

Show comment
Hide comment
@GBarkhatov

GBarkhatov Feb 6, 2017

+1 @dylang npm-check

+1 @dylang npm-check

@xgvargas

This comment has been minimized.

Show comment
Hide comment
@xgvargas

xgvargas Mar 30, 2017

If you have linked some personal package to global then you should use:

#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | grep -v @linked | cut -d: -f2)
do
    npm -g install "$package"
done

As this will not try to update your local linked package. Actually this should be the default case since it works even when you don't have linked packages.

If you have linked some personal package to global then you should use:

#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | grep -v @linked | cut -d: -f2)
do
    npm -g install "$package"
done

As this will not try to update your local linked package. Actually this should be the default case since it works even when you don't have linked packages.

@xgvargas

This comment has been minimized.

Show comment
Hide comment
@xgvargas

xgvargas 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.

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.

@callemo

This comment has been minimized.

Show comment
Hide comment
@callemo

callemo Apr 21, 2017

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

callemo commented Apr 21, 2017

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

@Noyabronok

This comment has been minimized.

Show comment
Hide comment
@Noyabronok

Noyabronok May 8, 2017

the one liner updated npm for me :(

the one liner updated npm for me :(

@hrushikesh09

This comment has been minimized.

Show comment
Hide comment
@hrushikesh09

hrushikesh09 Jun 25, 2017

+1 @dylan
npm -g i npm-check

+1 @dylan
npm -g i npm-check

@calpa

This comment has been minimized.

Show comment
Hide comment
@calpa

calpa Aug 6, 2017

+1 @dylang npm-check

calpa commented Aug 6, 2017

+1 @dylang npm-check

@jan-hudec

This comment has been minimized.

Show comment
Hide comment
@jan-hudec

jan-hudec 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.

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.

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