6

I frequently encounter path related problems while compiling or running an app.I have two versions of node in my system, one is from official repo, the other manually installed from source. Today I wanted to compile brackets, when I run npm install it asked me to use later version such as 1.4.20. Default version of it is in /usr/bin/npm which did't work. The manually installed one is in /usr/local/bin/npm

Is there any way to make /usr/local/bin/npm as default path using update-alternatives or another method?

For example you can set default text editor with

    sudo update-alternatives --config editor
6

I've found how to do that. At first I checked out default path of npm which is older version (1.3.10) in /usr/bin/npm , I noticed that it's a symbolic link to /usr/share/npm/bin/npm-cli.js I removed it

    sudo unlink /usr/bin/npm

Then I tried following command

   sudo update-alternatives --install /usr/bin/npm  npm /usr/local/bin/npm 10
   sudo update-alternatives --install /usr/bin/npm  npm /usr/share/npm/bin/npm-cli.js 20

Now I can easily switch between them using

  sudo update-alternatives --config npm      

It works well

| improve this answer | |
2

Since you mentioned node, I thought I might point out that this is a good opportunity to use the N installation manager for NodeJS. If I have a "higher level" package manager like this available, I'll typically use it over update-alternatives. It's generally less complicated than trying to track down important files on your own, IMO. That said, I think update-alternatives will still work.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.