6

I want to install the latest node (v6.2.0 at the time of writing) on Ubuntu. But as I do

sudo apt-get nodejs

This installed v0.10.37.

Can you please help me in installing the latest version of node js and also npm latest version?

Blaszard
  • 30,954
  • 51
  • 153
  • 233
Aman Gupta
  • 1,764
  • 4
  • 30
  • 58
  • That's probably the latest version available in your package manger. Maybe checkout [How can I update my nodeJS to the latest version?](http://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version) – Alexander O'Mara May 26 '16 at 17:18
  • @AlexanderO'Mara how can i completely remove node from my system. its all mess in here with multiple node_modules. – Aman Gupta May 26 '16 at 17:48

12 Answers12

10

This is very simple, Grab the Linux node distribution from here: https://nodejs.org/dist/v6.2.0/

Open Terminal and type below command:

sudo tar -C /usr/local --strip-components 1 -xzf ~/Downloads/node-v6.2.0-linux-x64.tar.gz

ls -l /usr/local/bin/node

That`s it.

Now check your node version by typing:

node -v
npm -v

One can install any version of node in Ubuntu using above steps.

Ashutosh Ranjan
  • 333
  • 2
  • 14
  • Since node is installed @ /usr/local/bin/ we can use follwing command to remove node completely: rm -rf /usr/local/bin/node. This should work. – Ashutosh Ranjan Dec 08 '17 at 05:01
7

There is official instruction:

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

Follow https://deb.nodesource.com/setup_6.x to read shell script before execute above commands.
You always must to know what you run, especially by sudo.

vp_arth
  • 14,461
  • 4
  • 37
  • 66
4

Any version of node install is very easy

Just click Node.js scroll down and go Installation instructions and chose which version you want to install

To Install 12.x version of node:

  1. Open your terminal [Ctrl+Alt+t]
  2. execute below command

Using Ubuntu

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

or

Using Debian, as root

curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
Md. Nasir Uddin
  • 151
  • 1
  • 13
3

To remove previous version use command

sudo npm cache clean -f
sudo npm install -g n

and then for latest version

sudo n latest

Or for stable version

sudo n stable
Rupesh
  • 850
  • 2
  • 13
  • 30
2

By far the most convenient way to install and manage node versions on your machine is the Node Version Manager a.k.a nvm. Just follow the installation instructions in the repo and after you have it installed run

nvm install 6.2.0
jahnestacado
  • 593
  • 3
  • 9
2

I would suggest installing through package manager to make sure it installs with accurate dependencies.

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

Also, use NPM

 sudo apt-get install npm

to install modules, like so:

npm install express
1

Install the package through the official download page, in a .deb format. Go ahead and grab the newest version here:

https://nodejs.org/download/release/latest/

Just go ahead and download your desired version and double-click on the downloaded .deb file, and you're good to go. npm comes with nodejs, btw.

RECOMMENDED READING

https://www.npmjs.com/package/npm

EDIT

If you wish to completely reinstall nodejs, check out the script located here:

https://gist.github.com/brock/5b1b70590e1171c4ab54

and check out this:

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

It says Mac OSX, but it'll work perfectly fine in ubuntu, too.

1

Install the snap package

The easiest method to install Node.js on Ubuntu is to use the snap package. Just search for node on Ubuntu Software store and install the first one.

Node.js on Ubuntu Software

Or if you prefer command line:

sudo snap install node --classic 

Alternate method: NVM

If you can't use snaps for some reason, like from a WSL environment, then Node Version Manager (NVM) is the way to go. It's safer than upgrading the node packages in Ubuntu to unsupported versions from PPAs or 3rd party repos, which may cause conflicts or breakages in apt package management system. Compared to NVM, manual installations from tarballs are harder to maintain and upgrade. Follow these steps to install the latest node using NVM:

Step 1: Install NVM

Run this command in Terminal:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

Step 2: Install node

Once NVM installation is complete, close and reopen Terminal. Then run this command:

nvm install node

Step 3: Check node version

Run these commands:

node --version
npm --version

If everything went well, you'll see the latest node and npm versions as output. That's all, node is installed and ready to run!


Note: This question is similar to the AskUbuntu question "How do I install the latest version of node.js?" and my answer equally applies. I'm reproducing my answer here to ensure a full complete answer exists rather than just a link.

1

depends on what version of latest nodejs you want to install if LTS version or current latest version, then from PPA

latest LTS version

apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt-get install nodejs

current latest version

apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
apt-get install nodejs

source: https://codesposts.com/ydOAwynW

uberrebu
  • 3,597
  • 9
  • 38
  • 73
0
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y nano git curl vim htop gnupg2 && curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && sudo apt-get install -y nodejs
Zoe
  • 27,060
  • 21
  • 118
  • 148
  • 5
    While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! In your specific case, it would be much more convenient if you would make a line break instead of using several `&&`. – Filnor Aug 13 '18 at 14:30
0

Install NodeJS 14x and npm 7x in Ubuntu 2020 LTS

  • Install Nodesource: curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  • Install NodeJS: sudo apt-get install -y nodejs
  • Install latest npm: npm install -g npm@latest
  • For certain npm packages to run: sudo apt install build-essential
Md. Shahariar Hossen
  • 1,367
  • 10
  • 11
0

The easiest way is using a single line command is sudo snap install node --classic

It installs the latest stable node version from snap store.