[FIXED] Use specific Node version in combination with specific npm version

Issue

For a client’s web project I work with two other developers. The frontend is built with quite a setup (gulp, foundation, bower, …) and started a few years ago. They both use a (never updated)

combination of Node v6.12.2 and npm v5.6.0.

As I had Node v10.x on my machine and the first attempts of running npm install after cloning the project failed, I’d like to use the exact same setup:

I setup nvm to use v6.12.2

$ \projectfolder nvm use v6.12.2 

The Terminal then states:

Now using node v6.12.2 (npm v3.10.10)

How can I tell my setup to use npm@5.6.0 along with node v6.12.2? I tried npm install npm@5.6.0 which then changes the used npm version, but also changes the used node version back.

I know nvm installs the respective npm version along with the node version. But is there a way to work with exactly this combination of versions the other developers use in my project?

Solution

After switching node versions with nvm use (and confirming you switched with node --version), you should globally update/downgrade npm with:

npm install -g npm@5.6.0 // -g arg is important

Switch back to other node version and it should be using its own version. Also see this npm article about installing npm versions.

If you want to know why it is installed globally: run in the command line:

ls -l $(which npm)

It returns

/home/USER_NAME/.nvm/versions/node/vNODE_VERSION/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

It’s a symlink to the global node_modules folder of that specific node version.

Answered By – axm__

Answer Checked By – Marilyn (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published