3

I have installed node and npm using following command in my Ubuntu machine:

sudo apt-get install nodejs npm

On checking version of installed, I could see following:

$ node -v && npm -v
v0.10.25
1.3.10

But I want nodejs version to be 4.2.0 or above. I am trying to install VSO Linux agent for a project. On executing node agent/vsoagent, I get error that node version should be 4.2.0 or above.

How do I install it and also make sure that the already installed ones are removed with node -v && npm -v gives me new version number?

Thanks

mscdex
  • 104,356
  • 15
  • 192
  • 153
Raji
  • 857
  • 6
  • 18
  • 37
  • 1
    https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions – ceejayoz Jul 28 '16 at 16:32
  • Thanks a lot Ceejayoz. I was able to get this link and executed **bold** curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - But it got hung after showing "working 100%" and nothing happened after that. – Raji Jul 28 '16 at 16:36
  • And also will "setup_4.x" install version greater than 4.2.0 or latest of 4.2 versions? – Raji Jul 28 '16 at 16:37
  • 1
    I highly recommend `nvm` (Node Version Manager). You can install whichever version(s) you want with it, and have multiple versions that you can easily switch between. See [my answer to a different question](http://stackoverflow.com/questions/20057790/what-are-the-differences-between-node-js-and-node/20058007#20058007) where I recommend it, for more information. – Paul Jul 28 '16 at 18:09
  • I used nvm. It works very fast and installs node with whatever version we are looking for. But on restarting server it goes away. Is there any way to make it permanent ? – Raji Jul 29 '16 at 08:12
  • If you use @Paulpro when you comment I'd get notified right away. You'll get notified of this, since I'm commenting on your post, but since it's not my post you need to reference my username with an @ for me to get notified. – Paul Jul 29 '16 at 15:22
  • @Raji Try running `nvm alias default stable`. Then restarting the server. – Paul Jul 29 '16 at 15:27

1 Answers1

1

You already have npm, so you can use n manager to install any version you want (4.4.4 for ex): maybe you should use sudo for global install:

npm install -g n 
n 4.4.4

Or

n latest

After that you can just run n to select version that you prefer. I use latest LTS and latest 6.x side-by-side and switching them anytime i want.

deksden
  • 774
  • 6
  • 13
  • Tried this option also. npm install -g n n 4.2.5 It gave me following output: install : node-v4.2.5 mkdir : /usr/local/n/versions/node/4.2.5 fetch : https://nodejs.org/dist/v4.2.5/node-v4.2.5-linux-x64.tar.gz ######################################################################## 100.0% installed : v4.2.5 But on checking version, it still points to old version. How do I update it to 4.2.5 and also the directory structure of 4.2.5 is different from the one which was installed initially. – Raji Jul 29 '16 at 08:13
  • Can you explain the options, please? In particular, what does `-g` do? – Michael Scheper Jun 19 '17 at 18:51
  • 1
    @MichaelScheper: sure. "-g" option for npm installs module "globally" makes them accesible from any project on whole system. Its not recommended to go global for regular dev/runtime modules, but CLI utilites like "n" is ok. (use "npm list -g --depth=0" to list all globally installed modules). More info - google for "npm global install" – deksden Jun 20 '17 at 18:03