15

This question already has an answer here:

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?

marked as duplicate by Ciro Santilli 新疆改造中心 六四事件 法轮功, Eric Carvalho, Zanna, Charles Green, waltinator Mar 6 '18 at 5:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

20

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
  • Thanks for your answer, I installed nodejs-legacy and npm but now when I type node, I get: bash: /usr/sbin/node: Does not exist file or directory – Gocht Nov 24 '15 at 23:57
  • Try remove nodejs and install again. – tarkhov Nov 25 '15 at 0:10
  • Done, now I got an error related to version when I tried to install Yeoman, my nodejs version is: v0.10.25, is this up to date? – Gocht Nov 25 '15 at 0:10
  • 1
    Right version, it's a conflict nodejs-legacy with your symlink created before. Just follow this steps: 1. sudo apt-get remove npm 2. sudo apt-get remove nodejs-legacy 3. sudo apt-get remove nodejs 4. sudo rm /usr/bin/node 5. sudo apt-get install nodejs 6. sudo apt-get install nodejs-legacy 7. sudo apt-get install npm – tarkhov Nov 25 '15 at 0:21
  • 1
    Removing and reinstall worked for me, Thanks a lot! NOw I can use the node command. – Gocht Nov 25 '15 at 14:54
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.

1

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.

  • When I installed nodejs with sudo apt-get install nodejs, it is successfull but when I tried just now to install yeoman, I got an error related to the node version. – Gocht Nov 25 '15 at 0:09
  • Maybe this discussion will help : node: command not found – Bilal Nov 25 '15 at 0:13
1

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.

  • 1
    Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Kevin Bowen Mar 5 '17 at 17:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.