34

I have two Ubuntu 12.10 machines: machine A is a VMWare VM and machine B is and old Acer laptop. On both machines, I installed node using apt-get. However machine A installs the main binary as /usr/bin/node and machine B as /usr/bin/nodejs. Here are some behaviors I observed:

  1. Both machine returns /usr/bin/node in response to the which node command. However, there is no such file on machine B.
  2. Issuing the command node works for machine A, not B. On B, I have to use nodejs instead.
  3. On B, there is a binary called /sbin/node, A does not have it.

These behaviors causes inconsistency problem when developing on both machines. For now, I worked around by renaming the binaries on B as such:

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

Is there a way to really fix this, so that node will be installed as /usr/bin/node instead of /usr/bin/nodejs?

Hai Vu
  • 491

7 Answers7

37

update: modified instructions below to use the nodejs-legacy package.(more info about node-legacy)

Try completely removing the conflicting node package:

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs

sudo apt-get install nodejs-legacy

# Confirm it worked
node --version       # v0.10.13
ls -la `which node`  # ... /usr/bin/node -> /etc/alternatives/node

This happened to me when I unwittingly installed the non-node.js node package. Although I did apt-get remove node before installing the correct nodejs package, I guess the --purge argument is required.

Background info:

There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed from node to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.

Leftium
  • 623
  • Thank you for the background info. At this point, I don't have any of these machines to try on, but I hope I can revisit some day soon. – Hai Vu Jul 15 '13 at 15:41
  • This doesn't get you a /usr/bin/node in Ubuntu 13.10. @user229115's answer below works, though. – Jim Stewart Jan 26 '14 at 07:42
  • 1
    So with Ubuntu 13.10 sudo apt-get install nodejs nodejs-legacy will give you the node binary as node.js But if you already installed the node (Amateur Packet Radio Node Program) you'll obviously need to remove it. – jonasfj Feb 20 '14 at 04:03
  • Seems like this answer doesn't work anymore... – Augustin Riedinger May 30 '14 at 09:09
  • 1
    @AugustinRiedinger: I updated my answer. I think the combination of both purging the 'misconfigured' packages and installing the nodejs-legacy package will work. – Leftium May 30 '14 at 16:24
  • 1
    Thanks it is very clear. Indeed it works when installing the nodejs-lecacy package which may be only a symlink to the nodejs executable actually... – Augustin Riedinger Jun 02 '14 at 09:01
  • I made my own symlink, after discovering that "apt-get install node" didn't do what I thought it did. – Warren P Jun 11 '15 at 15:01
16

On Ubuntu 13.10 all answers above did not work for me. It finally worked when I installed nodejs-legacy

sudo apt-get install nodejs-legacy

This correctly provided /usr/bin/node for me, so that e. g. nodemon can be used.

Teetrinker
  • 276
  • 2
  • 3
  • Any idea why we need to install this? Does it actually creates the symlink somehow? Why did node change the name of its executable to nodejs? – Augustin Riedinger May 30 '14 at 09:11
  • The name "node" conflicted with a much older program. See https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html and Leftium's answer below. – Robie Basak May 30 '14 at 17:02
11

Unfortunately for me, creating a symlink did not work. What did work for me though was creating an alias. In ~/.bashrc or ~/.bash_aliases (if ~/.bashrc loads this file), just add the following line:

alias node="nodejs"

Restart your bash session by typing bash into the console and your alias will now work.

Aust
  • 211
  • 2
    When I created a symlink, it did not work until I started another terminal. Try restarting your terminal... or my answer that works without symlinks/aliases ^^ – Leftium Jul 16 '13 at 22:36
  • @Leftium: You also need to run: source ~/.bashrc to reload the .bashrc file (if you want to avoid restarting the terminal) read more.. – Deepak Joy Cheenath Dec 12 '14 at 03:08
  • Symlinking at a new location almost certainly needs a hash node invocation in your existing terminals, because modern shells remember the location of commands that have been previously looked up in PATH. The hash builtin command in such shells tells them to redo the lookup, and remember the new location. – mtraceur Apr 15 '17 at 03:23
7

I think this is it:

sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

Using Debian alternatives.

user229115
  • 181
  • 1
  • 3
  • Thanks. This is the most direct way to remedy Ubuntu's decision on this matter. – Drew Apr 18 '14 at 12:08
  • @drew it looks like Ubuntu followed Debian's decision on this based on the Ubuntu bug https://bugs.launchpad.net/ubuntu/+source/node/+bug/1030421 . – Lloyd Dewolf Mar 01 '15 at 01:01
1

Late answer, but for up-to-date info...

If you install node.js using the recommend method from the node github installation readme, it suggests following the instructions on the nodesource blog article, rather than installing from the out of date apt-get repo, node.js should run using the node command, as well as the nodejs command, without having to make a new symlink.

This method from article is:

# Note the new setup script name for Node.js v0.12
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -

# Then install with:
sudo apt-get install -y nodejs

Note that this is for v0.12, which will get likely become outdated in the not to distant future.

Also, if you're behind a corporate proxy (like me) you'll want to add the -E option to the sudo command, to preserve the env vars required for the proxy:

curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -
Erresen
  • 279
1

On ubuntu 14.04 I had the same node problem. I had not working "node", and working "nodejs". I just did

sudo apt-get remove node

and right after that, node was running, and nodejs is running too :) I'm new to linux and that is a misstery to me. However Bower is running!!!

0
sudo getconf LONG_BIT
sudo uname -p
  • Confirm your CPU architecture
  • Find your node.js distribution in directory tree at https://nodejs.org/dist/ (note: various versions of various node.js distributions for various CPU architectures)

My desktop is currently Ubuntu 15.10 AMD64, so I will use the following URL in my installation example (again, distrib's vary):

sudo wget https://nodejs.org/dist/v5.0.0/node-v5.0.0-linux-x64.tar.gz

Then change directory to your download directory:

sudo cd /home/name/Downloads

From your download directory, execute the following:

sudo tar -C /usr/local --strip-components 1 -xzf node-v5.0.0-linux-x64.tar.gz

Confirm your node.js installation with the following:

sudo ls -l /usr/local/bin/node
sudo ls -l /usr/local/bin/npm

ref. http://www.hostingadvice.com/how-to/install-nodejs-ubuntu-14-04/