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:23

Apparently the solution differs between Ubuntu versions. Following worked for me on Ubuntu 13.10:

sudo apt-get install nodejs-legacy

HTH

Edit: Rule of thumb:

If you have installed nodejs but are missing the /usr/bin/node binary, then also install nodejs-legacy. This just creates the missing softlink.

According to my tests, Ubuntu 17.10 and above already have the compatibility-softlink /usr/bin/node in place after nodejs is installed, so nodejs-legacy is missing from these releases as it is no more needed.

查看更多
伤终究还是伤i
3楼-- · 2018-12-31 15:23

This happened to me as well.

node -v => 0.10.2
nodejs -v => 5.5.0

The issue was that I had installed node from source some time ago. Running

which node

always pointed to this local installation. Also,

echo NODE_PATH

pointed to the local installation.

deleting the directory with the source install didn't help. It just broke the node command. In the end, unsetting the NODE_PATH environmental variable and purging then reinstalling nodejs did the trick.

unset NODE_PATH
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs

After this,

node -v => 5.5.0

and npm install started to work for packages depending on Node => 5.0.

查看更多
骚的不知所云
4楼-- · 2018-12-31 15:25

This works for me:

alias node=nodejs

After following the instructions in this link.

查看更多
萌妹纸的霸气范
5楼-- · 2018-12-31 15:26

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 -

查看更多
几人难应
6楼-- · 2018-12-31 15:27

I had the same issue symbolic link helped me out: sudo ln -s /usr/bin/nodejs /usr/bin/node after that sudo npm install -g phantomjs-prebuilt

went smoothly

查看更多
浮光初槿花落
7楼-- · 2018-12-31 15:29

I am new to all this, but for me a simple alias worked:

alias node='env NODE_NO_READLINE=1 rlwrap nodejs'

at least for running things directly in bash and executing .js files.

查看更多
登录 后发表回答