; Date: Tue Apr 10 2018
The nvm script is an exceedingly useful tool for maintaining multiple Node.js versions while keeping your sanity. Running "npm install", I noticed a strange warning message from node-gyp about "NVM_NODEJS_ORG_MIRROR" being deprecated. Looking for the cause, I found a cause centered on nvm. Let's see how to fis this problem.
nvm and why is it needed?
Probably the best method for installing and updating Node.js is to install packages through the package manager for your operating system. That's easy, you type
sudo port install nodejs or
sudo apt-get install nodejs or some equivalent, and from that point onward the packaging system maintainers keep you up-to-date.
What if your operating system does not have Node.js packages available? What if Node.js packages are available, but they're woefully out of date? What if you need to support several Node.js versions, and are routinely switching between them?
nvm is meant to solve. It simplifies maintaining multiple side-by-side Node.js installs, and lets you easily switch between Node.js versions.
To install, go to: https://github.com/creationix/nvm
Then pick your preferred installation command between these two:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash $ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
Make sure to go to the Github page to get the latest version number rather than the number shown here.
After running the command, you'll be given a code snippet to add to your
$HOME/.profile so that
nvm is available to every command shell.
Once that's setup you can install a Node.js version by running
nvm install 9 (to get the latest Node.js 9.x) or whatever. The github page has full information.
What's it mean that NVM_NODEJS_ORG_MIRROR is deprecated?
Let's now talk about the deprecation message causing me to write this posting.
npm install output for a project reading:
$ npm install npm WARN registry Using stale data from https://registry.npmjs.org/ because the host is inaccessible -- are you offline? npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation. > email@example.com install /Volumes/Extra/book-4th/chap09/users/node_modules/dtrace-provider > node-gyp rebuild || node suppress-error.js gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR ACTION binding_gyp_ndtp_target_build_ndtp . TOUCH Release/obj.target/ndtp.stamp > firstname.lastname@example.org install /Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3 > node-pre-gyp install --fallback-to-build [sqlite3] Success: "/Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3/lib/binding/node-v59-darwin-x64/node_sqlite3.node" is installed via remote npm WARN email@example.com No description npm WARN firstname.lastname@example.org No repository field. added 232 packages in 24.384s
The warning about NVM_NODEJS_ORG_MIRROR being deprecated and such was irksome, and I wanted to find the solution.
After some searching, I got to this issue: https://github.com/creationix/nvm/issues/1429
This is where the
nvm maintainers fixed the deprecation warning. The discussion refers to earlier features in
node-gyp - that
node-gyp formerly paid attention to environment variables placed by
node-gyp issue discussed the warning:
Sometime in early 2016, the
node-gyp tool began printing that message and there was an effort to work with the
nvm maintainer to get the two in sync. That
node-gyp paid attention to
nvm environment variables was a bug.
node-gyp is the tool used by Node.js and npm to build native-code packages. We generally don't directly run
node-gyp but instead it is run as a side effect of installing packages requiring compilation using
To cut to the chase -- the
nvm issue made it clear that
nvm fixed this problem in early 2017. The question then is why does this message still get printed?
$ ls -l $NVM_DIR/nvm.sh -rwxr-xr-x 1 david staff 70948 Feb 8 2016 /Users/david/.nvm/nvm.sh
This is why -- my
nvm was very much out of date.
Another piece of data is these environment variables:
$ env | grep MIRROR NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
If one unsets those variables, then reruns
. $NVM_DIR/nvm.sh those variables get reinitialized. Unset the variables, then rerun
npm install and the deprecation warnings are not printed.
We have already seen the solution. At the
nvm Github page we see that the install script can also be used to update an existing
Therefore fixing the problem is easy enough. Just rerun the
nvm installer, and then update the
$HOME/.bashrc files because there is a new initialization script. All of which is explained here:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 12540 100 12540 0 0 12540 0 0:00:01 0:00:01 --:--:-- 7437 => nvm is already installed in /Users/david/.nvm, trying to update using git => => Compressing and cleaning up git repository => Appending nvm source string to /Users/david/.bashrc => Appending bash_completion source string to /Users/david/.bashrc => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Having done the above, and rerunning
. $NVM_DIR/nvm.sh, neither of those environment variables exist. And we get this clean output from
ls -l $NVM_DIR/nvm.sh -rw-r--r-- 1 david staff 108382 Apr 10 13:16 /Users/david/.nvm/nvm.sh . $NVM_DIR/nvm.sh env | grep MIRROR rm -rf node_modules/ npm install email@example.com install /Volumes/Extra/book-4th/chap09/users/node_modules/dtrace-provider node-gyp rebuild || node suppress-error.js ACTION binding_gyp_ndtp_target_build_ndtp . TOUCH Release/obj.target/ndtp.stamp firstname.lastname@example.org install /Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3 node-pre-gyp install --fallback-to-build [sqlite3] Success: "/Volumes/Extra/book-4th/chap09/users/node_modules/sqlite3/lib/binding/node-v59-darwin-x64/node_sqlite3.node" is installed via remote npm WARN email@example.com No description npm WARN firstname.lastname@example.org No repository field. added 232 packages in 24.74s