nodejs vs node on ubuntu 12.04

2018-12-31 14:30发布

I installed nodejs on ubuntu from instructions given here

When I write node --version in the terminal I see this :
-bash: /usr/sbin/node: No such file or directory

I can see node in the /usr/sbin/ directory, though.

Writing npm --version shows 1.3.5
Writing nodejs --version shows v0.10.15

Also, I can see node in the /usr/bin/ directory.

So, how do I get node working?

Also, If I use zsh instead of bash, then node command works.

20条回答
妖精总统
2楼-- · 2018-12-31 15:04

I think this is it:

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

Using Debian alternatives.

查看更多
忆尘夕之涩
3楼-- · 2018-12-31 15:05

https://nodejs.org/en/download/

Download .pkg file on your mac and install it. it directly works.

➜  ~ which node
/usr/local/bin/node
➜  ~ node --version
v10.11.0
➜  ~ which npm
/usr/local/bin/npm
➜  ~ npm --version
6.4.1
查看更多
泪湿衣
4楼-- · 2018-12-31 15:06

It's optional to remove the existing node and nodejs, but have to do alternatively install the latest 7.x nodejs.

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
查看更多
梦寄多情
5楼-- · 2018-12-31 15:09

I have the same issue in Ubuntu 14.04.

I have installed "nodejs" and it's working, but only if I'm use command "nodejs". If I try to use "node" nothing happens.

I'm fixed this problem in next way:

  1. Install nodejs-legacy

    sudo apt-get install nodejs-legacy

After that, when I type "node" in command line I'm get an error message "/usr/sbin/node: No such file or directory"

  1. Second, what I did, it's a symbolic link on "nodejs":

    sudo ln -s /usr/bin/nodejs /usr/sbin/node
查看更多
回忆,回不去的记忆
6楼-- · 2018-12-31 15:13

You need to manually create a symlink /usr/bin/node. Shortcut for bash compatible shells:

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

Or if you use non-standard shells, just hardcode the path you find with which nodejs:

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

Later edit

I found this explanation in the link you posted

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.

Later later edit

It's been a while since I answered this. Although the solution I posted up here worked for me several times, users have reported a few more solutions within the comments:

From @user229115

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

From AskUbuntu (user leftium)

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs
查看更多
流年柔荑漫光年
7楼-- · 2018-12-31 15:14

How about using the official instructions from the nodejs site:

For v7:

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

For v6:

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

For v4:

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

I've tested these from Windows bash (via subsystem for Linux - 14.04) and raspbian (ARM Debian based). Running sudo apt-get install -y nodejs without first running the setup script will result in you getting node 0.10.

If you are planning on installing native npm modules requiring build, also run:

sudo apt install -y build-essential

Note: this is the recommended path for any Debian based distro across all architectures.

查看更多
登录 后发表回答