List and Update Global Packages with npm and Yarn

Many times we globally install packages then forget how many packages we have installed or that we need to update them.

Below are a set of commands to list globally installed packages and a set of commands to updated them with NPM and Yarn.

[topads][/topads]

npm

To update npm packages we have npm-check. First you will have to install it globally

npm i npm-check -g

Then to list packages that need to be updated

npm-check -gu

We pass -g flag to do a global search, then u flag to update. This will give us an interactive menu where you can move up/down the list of packages, then press space bar to select them, finally press Enter key to update the selected packages.

Updating npm packages
Updating npm packages

Now to list all of your packages

npm list -g --depth=0

Again we pass the -g flag to do a global search and — depth=0 to give us a clean list. If you don’t then it will give us a very verbose list, listing all of the dependencies for each package as well.

Listing npm packages
Listing npm packages

Yarn

With yarn we don’t have to install another package, just run

yarn global upgrade-interactive

We pass the global flag to do a global search. And as with npm, you can move up/down the list of packages, then press space bar to select them, finally press Enter key to update the selected packages.

Upgrading yarn packages
Upgrading yarn packages

To list global packages

yarn global list
Listing yarn packages
Listing yarn packages

[bottomads][/bottomads]

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.