How to run NVM command from bash script

I want to run a command NVMfrom bash script ie nvm use 0.12.7. So I wrote a bash file:

#!/bin/bash
. ~/.nvm/nvm.sh
nvm use 0.12.7

And then run the command in the terminal as sudo ./script.sh(script.sh is my bash file where the code is written above). This gives me the result Now using node v0.12.7. But when I check if the version was activated or not, I did not find any influence. those. I ran the command nvm lsand found the result as:

v0.12.0
v0.12.7

This means that the version has 0.12.7not been activated. So, what things should I write in a bash script since I can activate the node version from the bash file.

+4
source share
1 answer

nvm , sudo . , sudo nvm.

, , , -. , "" .

, script . () . script .

~/bin/nvm-use-4 script:

. /usr/local/opt/nvm/nvm.sh
nvm use 4

:

prawie:~$ nvm current
v0.10.29
prawie:~$ . nvm-use-4
Now using node v4.2.1
prawie:~$ nvm current
v4.2.1

sudo , , , , sudo'ed -.

, , . . , node.js , .profile, .bashrc :

nvm use 0.12.7
+7

Source: https://habr.com/ru/post/1621198/


All Articles