Ubuntu 14.04: How to install specific version of nodeJS?

I used the following commands to install nodeJS version 8.x

1. sudo apt-get purge nodejs npm
2. curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
3. sudo apt-get install -y nodejs

When I run the command

node -v 

it shows v4.2.6 instead of the latest 8.x versions. Here is a screenshot.

NodeJS Installation

Upvotes: 3

Views: 10995

Answers (2)

Ivan Beldad
Ivan Beldad

Reputation: 2371

Use nvm to handle multiple nodejs versions.

Installing nvm

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

or

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

Installing node

nvm install <version>

Using desired version

nvm use <version>

Upvotes: 6

pzaenger
pzaenger

Reputation: 11973

First install Node.js via apt-get (e.g. v8):

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

Once you have installed Node.js, use the npm package n to switch to any version:

Simply execute n <version> to install a version of node. If <version> has already been installed (via n), n will activate that version.

Install n as global package and use n to install the latest version of Node.js:

npm i -g n
n latest

Upvotes: 7

Related Questions