Cannot install packages using node package manager in Ubuntu

  1. Install nvm first using:

    curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
    
  2. Run command

    source ~/.profile
    
  3. Now run this and this will show will all installed or other versions of packages:

    nvm ls-remote
    
  4. Installed packages will be in green. Install whatever version you want:

    nvm install 6.0.0
    
  5. Check where is not installed:

    which node
    
  6. Check current version:

    node -v
    
    n=$(which node);
    n=${n%/bin/node}; 
    chmod -R 755 $n/bin/*; 
    sudo cp -r $n/{bin,lib,share} /usr/local
    

TL;DR:

sudo apt-get install nodejs-legacy

First of all let me clarify the situation a bit. In summer 2012 Debian maintainers decided to rename Node.js executable to prevent some kind of namespace collision with another package. It was very hard decision for Debian Technical Committee, because it breaks backward compatibility.

The following is a quote from Committee resolution draft, published in Debian mailing list:

  1. The nodejs package shall be changed to provide /usr/bin/nodejs, not /usr/bin/node. The package should declare a Breaks: relationship with any packages in Debian that reference /usr/bin/node.

  2. The nodejs source package shall also provide a nodejs-legacy binary package at Priority: extra that contains /usr/bin/node as a symlink to /usr/bin/nodejs. No package in the archive may depend on or recommend the nodejs-legacy package, which is provided solely for upstream
    compatibility. This package declares shall also declare a Conflicts: relationship with the node package.

<...>

Paragraph 2 is the actual solution for OP's issue. OP should try to install this package instead of doing symlink by hand. Here is a link to this package in Debian package index website.

It can be installed using sudo apt-get install nodejs-legacy.

I have not found any information about adopting the whole thing by NPM developers, but I think npm package will be fixed on some point and nodejs-legacy become really legacy.


You can also install Nodejs using NVM or Nodejs Version Manager There are a lot of benefits to using a version manager. One of them being you don't have to worry about this issue.


Instructions:


sudo apt-get update
sudo apt-get install build-essential libssl-dev

Once the prerequisite packages are installed, you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download and install it with the following syntax:

curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh

This will download the script and run it. It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.

To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:

source ~/.profile

Now that you have nvm installed, you can install isolated Node.js versions.

To find out the versions of Node.js that are available for installation, you can type:

nvm ls-remote
. . .

v0.11.10
v0.11.11
v0.11.12
v0.11.13
v0.11.14

As you can see, the newest version at the time of this writing is v0.11.14. You can install that by typing:

nvm install 0.11.14

Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:

nvm use 0.11.14

When you install Node.js using nvm, the executable is called node. You can see the version currently being used by the shell by typing:

node -v

The comeplete tutorial can be found here


Try linking node to nodejs. First find out where nodejs is

whereis nodejs

Then soft link node to nodejs

ln -s [the path of nodejs] /usr/bin/node 

I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.