How to switch root user Nodejs version?

I ran into a problem as posted here , and reported that the cause might be the nodejs version.

As shown below, the node version is fine.

$node -v
v7.2.0

But this gives me an abnormal version of the root user that is used by the crontab process.

$sudo su
$node -v
v0.10.42

I tried $n rm 0.10.42or $n 7.2.0failed many times to fix the problem

Can anyone help? I want the crontab process to use the correct version of nodejs.

+4
source share
3 answers

I will find out that I can just add the correct path which nodeto $ PATH.

$which node
/usr/local/bin/node
$sudo su
$which node
/usr/bin/node
$export PATH=$PATH:/usr/local/bin
$node -v
v7.2.0
+1
source

, node .

$sudo su
$node -v
v0.10.42  //old version
$which node
/usr/bin/node
$mv /usr/bin/node /usr/bin/node.bk  //rename the old node
$node -v
bash: /usr/bin/node: No such file or directory
$n bin 7.2.0  //find out the path of the new node installed
/usr/local/n/versions/node/7.2.0/bin/node
$cp /usr/local/n/versions/node/7.2.0/bin/node /usr/bin/node  //replace
$node -v
v7.2.0  //success
0

Perhaps you can try using nvmnode version control. please install nvmby commandcurl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

try exec nvm install versionto install which version you want and use nvm use versionto select what you want.

0
source

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


All Articles