-1

I have come across ReactJS and React Native. ReactJS is brilliant, super fast and works fine on Node v0.10. But, React Native needs v4.x as a prerequisite. So, when I run any react-native command, it fails and says Node 4 is required.

I have tried several times and many ways to update Node, but, have failed.

First followed Installation Instructions -

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash
sudo apt-get install -y nodejs

I ended up with the following message-

root@purvotara:/# apt-get install -y nodejs
Reading package lists... Done
Building dependency tree      
Reading state information... Done
nodejs is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Then, there was Manual Installation way of installing.

add-apt-repository -y -r ppa:chris-lea/node.js
rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
echo 'deb https://deb.nodesource.com/node/dists/trusty/Release main' > /etc/apt/sources.list.d/nodesource.list
echo 'deb-src https://deb.nodesource.com/node/dists/trusty/Release main' > /etc/apt/sources.list.d/nodesource.list
apt-get update
apt-get install nodejs

Still, ended up with -

nodejs is already the newest version.

I tried to purge and auto-remove my current v0.10 node and tried to freshly install, not sure if its still picking the install from the cache, but, v0.10 got installed.

Also followed linoxide article on the same. A .configure and make install didn't seem to work as well.

What am I doing wrong? I am stuck for hours.

Went over several other links to resolve other issues(they are resolved now)-

Uninstalling node

Failed to fetch Trusty

Community
  • 1
  • 1
bozzmob
  • 12,364
  • 16
  • 50
  • 73
  • So which version `node --version` is showing now? – Manwal Oct 28 '15 at 05:17
  • It shows v0.10 when I do node -v – bozzmob Oct 28 '15 at 05:18
  • 2
    Have to tried installing different version using `NVM`? – Manwal Oct 28 '15 at 05:18
  • When I execute the CURL command and run scripts, it fetches all content w.r.t 4.x, but, later, when I do an INSTALL, it says, its already upto date and version would be 0.10 – bozzmob Oct 28 '15 at 05:19
  • @Manwal No I haven't tried NVM. I am not sure, but, read it somewhere it was used earlier(than npm) and not sure. Please correct me if I am wrong and guide me to the solution. – bozzmob Oct 28 '15 at 05:21
  • 2
    Actually you can install `NVM` and switch version of node anytime. This link may help you to download https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps – Manwal Oct 28 '15 at 05:28
  • Oh! I wasn't aware of it. I will check it and update soon. – bozzmob Oct 28 '15 at 05:30
  • WOW! That was the solution! Classy! NVM got things working for me. Thanks a lot @Manwal . – bozzmob Oct 28 '15 at 12:58
  • Great that also helped me one. Enjoy node. That's why its full form is `Node Version Manager`. – Manwal Oct 28 '15 at 12:59

3 Answers3

2

Use n. npm install -g n then you can switch to any version of node using a command like this n v4.1.2 https://www.npmjs.com/package/n

n uses /usr/local/bin/node for n to work properly on debian based systems, create a symlink to point to this directory.

sudo ln -s /usr/local/bin/node /usr/bin/node
Holger Will
  • 7,228
  • 1
  • 31
  • 39
  • This looks interesting! I will try it out and update the post soon. – bozzmob Oct 28 '15 at 05:29
  • Still facing the same problem. I installed 4.2.1, but, v0.10 is being shown. Updated as a part of answer. Please have a look. – bozzmob Oct 28 '15 at 12:49
1

@Holger This was the result of using 'n'. I have added this as an answer, as I want to bring more clarity in the code and solution itself.

Still facing the same problem. I installed 4.2.1, but, v0.10 is being shown.

root@purvotara:/# n 4.2.1

 install : node-v4.2.1
   mkdir : /usr/local/n/versions/node/4.2.1
   fetch : https://nodejs.org/dist/v4.2.1/node-v4.2.1-linux-x64.tar.gz
 installed : v4.2.1

root@purvotara:/# n
root@purvotara:/# node -v
v0.10.25

I used NVM and the issue is solved.

bozzmob
  • 12,364
  • 16
  • 50
  • 73
  • 2
    mmmh, you might try to uninstall the original packages... `sudo apt-get remove nodejs`... i'm not sure it helps though – Holger Will Oct 28 '15 at 13:01
  • Yes. I will try it out! This 'n' looks clean. I will further investigate and get it working. Thanks for the help. – bozzmob Oct 28 '15 at 13:03
-2

You can Do it Two ways. First try second step It must work for you.

1 Uninstall First version and Reinstall Other one 4.1.2 is latest as per my knowledge.

2 Click Here Follow steps.

sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
source ~/.profile
nvm ls-remote
nvm install 4.*.*   // Latest version choose here
nvm use 4.*.*    // Latest version also here
node -v   // Check your version
Gunjan Patel
  • 2,342
  • 4
  • 24
  • 45