Skip to content

Instantly share code, notes, and snippets.

@othiym23
Created September 20, 2014 19:36
Show Gist options
  • Save othiym23/4ac31155da23962afd0e to your computer and use it in GitHub Desktop.
Save othiym23/4ac31155da23962afd0e to your computer and use it in GitHub Desktop.
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
@martin-braun
Copy link

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)
done

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