how to use "update-alternatives" to manage multiple installed version of the same app
Solution 1
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
Solution 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.
Related videos on Youtube
Comments
-
kenn almost 2 years
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 usingupdate-alternatives
or another method?For example you can set default text editor with
sudo update-alternatives --config editor
-
s3lph almost 10 yearsRead this extended manpage: linux.die.net/man/8/update-alternatives
-