Install Node.js in Ubuntu 14.04 [duplicate]

I installed Node.js with:

sudo apt-get install nodejs

But when I type in a console node I get nothing, no command not found, no any error. But when I type nodejs I get the Node.js prompt >.

Now, I can't install anything with npm, I tried to install yeoman with: sudo npm install -g yo but I got an error, something related to node. I tried to change the command with:

sudo ln -s /usr/bin/nodejs /usr/bin/node

But still nothing happens when I type node

What is the right way to install Node.js on Ubuntu? Or what am I doing wrong? Or what am I missing?


Solution 1:

Need install nodejs-legacy package, it's a symlink bug fix: sudo apt-get install nodejs-legacy. Then install npm: sudo apt-get install npm. And right way to install Node.js:

  1. sudo apt-get install nodejs
  2. sudo apt-get install nodejs-legacy
  3. sudo apt-get install npm

Solution 2:

Generally speaking, loading arbitrary data from a URL into a root shell session is not a good idea and I wish people would stop peddling it as a solution for everything - "Please just run this script I'm sending you, and also while we're at it - I have a bridge you'd probably be interested in purchasing".

As an alternative, here's the "Ubuntu Way" of doing the same, where you can see how the system is being updated and know what repos and what keys are added to your system configuration:

apt-key adv --keyserver keyserver.ubuntu.com --recv 68576280
apt-add-repository "deb https://deb.nodesource.com/node_5.x $(lsb_release -sc) main"
apt-get update
apt-get install nodejs

This is for the latest (at time of writing) Nodejs version 5. Other versions can also be gotten with a simple change to the repo URL - consult nodesource.com documentation for details.

Solution 3:

You can install Node.js Using a PPA:

First, you need to install the PPA in order to get access to its contents:

curl -sL https://deb.nodesource.com/setup | sudo bash -

You can install the Node.js package by typing:

sudo apt-get install nodejs

The nodejs package contains the nodejs binary as well as npm, so you don't need to install npm separately. However, in order for some npm packages to work (such as those that require building from source), you will need to install the build-essentials package:

sudo apt-get install build-essential

For More information take a look at this page.

Solution 4:

Official instructions:

https://nodejs.org/en/download/package-manager/

Simply scroll down to the "Debian and Ubuntu based Linux distributions" section, and you'll find the following commands for installing the latest versions..

Ie, for the latest NodeJS 7.x :

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -

sudo apt-get install -y nodejs

For ubuntu, you might also want to install the optional build tools (recommended though, saves you from future headaches ssince notable npm packages USE it)

sudo apt-get install -y build-essential

Note: The instructions already installs both NodeJS & NPM, hence after doing so, you can already go "npm install whateveryouwantgoeshere -g" for any npm package.