Skip to content

Instantly share code, notes, and snippets.

@DeeDeeG
Created May 27, 2021 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeeDeeG/d95a79b590dae05fa7cbbe4fd34c06b2 to your computer and use it in GitHub Desktop.
Save DeeDeeG/d95a79b590dae05fa7cbbe4fd34c06b2 to your computer and use it in GitHub Desktop.
Updating npm's node-gyp (take 2)
diff --git a/Updating-npm's-bundled-node-gyp.md b/Updating-npm's-bundled-node-gyp.md
index 8dc7697..b9bfec6 100644
--- a/Updating-npm's-bundled-node-gyp.md
+++ b/Updating-npm's-bundled-node-gyp.md
@@ -12,11 +12,12 @@ Unix is easy. Just run the following command. Use `sudo` if necessary.
``` bash
$ [sudo] npm explore npm -g -- npm install node-gyp@latest
+$ [sudo] npm explore npm/node_modules/npm-lifecycle -g -- npm install node-gyp@latest
```
## Windows
-Windows is a bit tricker, since `npm` gets installed to the "Program Files" directory, which needs admin privileges in order to modify on current Windows. Therefore, run the following commands __inside a `cmd.exe` started with "Run as Administrator"__:
+Windows is a bit tricker, since `npm` might be installed to the "Program Files" directory, which needs admin privileges in order to modify on current Windows. Therefore, run the following commands __inside a `cmd.exe` started with "Run as Administrator"__:
First we need to find the location of `node`. If you don't already know the location that `node.exe` got installed to, then run:
@@ -37,10 +38,20 @@ Now `cd` to the directory that `node.exe` is contained in, and with `node_module
$ cd "C:\Program Files\nodejs\node_modules\npm"
```
-Now you can finally run:
+Now you can run:
``` bash
-$ npm install -g node-gyp@latest
+$ npm install node-gyp@latest
```
-note: i found that the -g on windows 7 is not correct. It gets installed in C:\Users\<name>\AppData\Roaming\npm\node_modules\gyp which is not the directory where node is installed C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\...
\ No newline at end of file
+Now `cd` to the `npm-lifecycle` directory:
+
+```bash
+$ cd node_modules\npm-lifecycle
+```
+
+Now you can finally run (again):
+
+``` bash
+$ npm install node-gyp@latest
+```

npm bundles its own, internal, copy of node-gyp. This internal copy is independent of any globally installed copy of node-gyp that you may have installed via npm install -g node-gyp.

This means that while node-gyp doesn't get installed into your $PATH by default, npm still keeps its own copy to invoke when you attempt to npm install a native addon.

Sometimes, you may need to update npm's internal node-gyp to a newer version than what is installed. A simple npm install -g node-gyp won't do the trick since npm will still continue to use its internal copy over the global one.

So instead:

Linux, Mac OS X, Solaris, etc.

Unix is easy. Just run the following command. Use sudo if necessary.

$ [sudo] npm explore npm -g -- npm install node-gyp@latest
$ [sudo] npm explore npm/node_modules/npm-lifecycle -g -- npm install node-gyp@latest

Windows

Windows is a bit tricker, since npm might be installed to the "Program Files" directory, which needs admin privileges in order to modify on current Windows. Therefore, run the following commands inside a cmd.exe started with "Run as Administrator":

First we need to find the location of node. If you don't already know the location that node.exe got installed to, then run:

$ npm install -g which
$ which node

As an alternative to the above, those on Windows Server 2003 and later (this includes Windows 7) can run:

$ where node

Now cd to the directory that node.exe is contained in, and with node_modules\npm at the end. i.e.:

$ cd "C:\Program Files\nodejs\node_modules\npm"

Now you can run:

$ npm install node-gyp@latest

Now cd to the npm-lifecycle directory:

$ cd node_modules\npm-lifecycle

Now you can finally run (again):

$ npm install node-gyp@latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment