NVM (Node Version Manager) is the best way to run multiple versions of NodeJS on the same machine. It's not only for Windows but in this post I will talk about my experience to install NVM on a Windows machine without Admin Rights.
The NVM meaning is node version manager, according to the official document, something we can know: This way is more recommend than node installer. You can install and switch between multiple versions of node and npm in your device.
The below list of commands (source: digitalocean) seems to fix the problem
n=$(which node); \
n=${n%/bin/node}; \
chmod -R 755 $n/bin/*; \
sudo cp -r $n/{bin,lib,share} /usr/local
The above command is a bit complicated, but all it's doing is copying whatever version of node you have active via nvm into the /usr/local/
directory (where user installed global files should live on a linux VPS) and setting the permissions so that all users can access them.
Hope this helps!
My solution is to create symbolic links from the versions of node
and npm
I'm using to /usr/local/bin
:
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/node" "/usr/local/bin/node"
sudo ln -s "$NVM_DIR/versions/node/$(nvm version)/bin/npm" "/usr/local/bin/npm"
This makes npm
and node
available to all users.
The fundamental reason is because nvm
is not a real program. It's a bash function that gets loaded in the user's .profile
, .bashrc
, or ... So sudo
doesn't automatically pick it up from the $PATH like most other programs.
An alternative node version manager is n
: https://github.com/tj/n . That is a real program, so sudo
will pick it up via the $PATH without any hacks (as long as sudo
has /usr/local/bin
in its $PATH).
sudo npm install -g n # install 'n' globally
which n # should be /usr/local/bin/n
sudo n lts # need sudo to switch node versions
node --version # v6.10.0
sudo node --version # v6.10.0
Your problem is, that nvm
is not in the path when you use sudo
.
So type
$ which nvm
and the result will be something like
/home/abc/mynvm/nvm
Try again now with sudo
:
sudo /home/abc/mynvm/nvm use v0.10.23
I assume you then run into the issue that the root user can't find the 0.10.13-version, but lets see the next error message...
When using nvm you do not need
sudo
to globally install a module withnpm -g
, so instead of doingsudo npm install -g grunt
, do insteadnpm install -g grunt
In my case, I need to sudo npm run start
which needs the access to some file requiring root access. According to this issue,
You don't use
sudo
. You should instead chmod/chown the file so that the user that has nvm has access to the file;.
The maintainer of nvm strongly believe we don't need to sudo
:P
I had your problem too. Finally I have worked around it. Here is my solution:
apt-get purge nodejs
.After restarting your terminal, you can run the command sudo nvm ls
.
$ sudo bash -ic "nvm use stable; npm -v"
Now using node v6.3.1 (npm v3.10.3)
3.10.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With