Found myself at a later version of NPM that I didn't want, and had trouble finding the resources online to explain how to go to a lower version.
Was at 1.2, did npm update npm -g
and found myself at 2.0 and then was not able to go down to the desired 1.4.
If you find yourself at a more current version than you wish, follow these steps:
- Wipe out your current version of npm
>sudo npm uninstall npm -g
-
Download the
install.sh
file from the npm registry: [http://npmjs.org/install.sh] -
Open
install.sh
in a text editor such as Sublime and find the following code:
t="${npm_install}"
if [ -z "$t" ]; then
# switch based on node version.
# note that we can only use strict sh-compatible patterns here.
case $node_version in
0.[012345].* | v0.[012345].*)
echo "You are using an outdated and unsupported version of" >&2
echo "node ($node_version). Please update node and try again." >&2
exit 99
;;
v0.[678].* | 0.[678].*)
echo "install [email protected]"
t=1.1
;;
*)
echo "install npm@latest"
t="latest"
;;
esac
fi
Determine which branch belongs to you. For example, if you are using node version 0.8, then you'd want to change echo "install [email protected]"
to the proper version number of npm that you want, such as
echo "install [email protected]"
t=1.4
- Run the install.sh script:
sh install.sh
You should now have the desired version of npm install on your system. Remember to install any modules you may have deleted in this process.
My 2 cents for whoever ends up here
Context :
I got on npm v7 for some reason, but was using node 8 thus giving incompatible warning. Wanted to revert to npm v6.
Problem:
$ npm install -g npm@6
succeeded without errors but$ npm -v
still showed v7.Solution:
While I have no doubt this gist would work, I tried another (easier) method - basically removing the symlink of npm v7.
$ which npm
showed/usr/local/bin/npm
-->/usr/local/lib/node_modules/npm
I rmed above node_modules and doing
$ npm -v
showed v6 as it should!Note:
I have an npmrc with prefix=~/.npm-global, where my npm v6 (and other global modules) are installed (as opposed to the default dir).
I'd suggest removing the symlink first and see if works before rm just to be safe.