Offer update by current package manager


(Jan Poboล™il) #1

Currently when update is available it will print something like this:

   โ”‚                                                               โ”‚
   โ”‚       New minor version of npm available! 6.1.0 โ†’ 6.2.0       โ”‚
   โ”‚   Changelog:   โ”‚
   โ”‚               Run npm install -g npm to update!               โ”‚
   โ”‚                                                               โ”‚

The last sentence is problematic in case NPM is installed by some other package manager, e.g. homebrew.

It should recognize some common package managers, test if current NPM is installed by this manager and then offer command for this manager. So in my case it should print:
Run brew update npm to update!

(Kat Marchรกn) #2

I would love an RFC for this. We just need someone to take the time to research how to even detect this and be specific about the alternative installers weโ€™re going to support. Would you be interested in that?

(Jan Poboล™il) #3

Just partly:

With brew you can test if it is installed by it:

brew ls --versions npm

It will print installed versions of package containing npm (usually node) or nothing if npm is not installed with brew.
If this command prints something you can safely run brew upgrade npm (it will do brew update if not already done today and upgrade node).

It just have one imperfection: NPM checks itโ€™s new releases, but not if this new version has been released already in node package in brew repository. This will probably be and issue also with other package managers.

(Alex Chaffee) #4
  • the correct command for upgrading npm in homebrew would be brew upgrade not brew update โ€“ specifically brew upgrade node since node and npm are bundled together by homebrew
  • even that doesnโ€™t work right now! Neither brew upgrade npm, brew upgrade node, nor brew link npm afterward, installs the actual latest version of npm in /usr/local/bin; instead it reports Error: npm 11.3.0_1 already installed

I know this is an error in Homebrew, not NPM per se, but Iโ€™m mentioning it here for reference.

Various solutions exist, YMMV. For me it was some combination of

brew upgrade node
brew unlink node
sudo chown -R alex /usr/local/lib
brew link --overwrite node