本文翻译自:nodejs vs node on ubuntu 12.04
I installed nodejs on ubuntu from instructions given here 我在这里给出的指令上安装了ubuntu上的nodejs
When I write node --version
in the terminal I see this : 当我在终端中编写node --version
时,我看到: -bash: /usr/sbin/node: No such file or directory
I can see node in the /usr/sbin/
directory, though. 不过,我可以在/usr/sbin/
目录中看到节点。
Writing npm --version
shows 1.3.5
写npm --version
显示1.3.5
Writing nodejs --version
shows v0.10.15
编写nodejs --version
显示v0.10.15
Also, I can see node in the /usr/bin/
directory. 另外,我可以在/usr/bin/
目录中看到节点。
So, how do I get node
working? 那么,我如何让node
工作?
Also, If I use zsh instead of bash, then node
command works. 此外,如果我使用zsh而不是bash,则node
命令有效。
#1楼
参考:https://stackoom.com/question/1E4U0/ubuntu-上的nodejs-vs-node
#2楼
You need to manually create a symlink /usr/bin/node
. 您需要手动创建符号链接/usr/bin/node
。 Shortcut for bash compatible shells: bash兼容shell的快捷方式:
sudo ln -s `which nodejs` /usr/bin/node
Or if you use non-standard shells, just hardcode the path you find with which nodejs
: 或者,如果您使用非标准shell,只需使用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. 与节点包(业余分组无线电节点程序)存在命名冲突,并且nodejs二进制文件已从节点重命名为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. 您需要将/ usr / bin / node符号链接到/ usr / bin / nodejs,或者您可以卸载业余数据包无线电节点程序以避免这种冲突。
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 来自@ user229115
sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
From AskUbuntu (user leftium) 来自AskUbuntu(用户leftium)
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs
#3楼
I think this is it: 我觉得这就是:
sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
Using Debian alternatives. 使用Debian替代品。
#4楼
Apparently the solution differs between Ubuntu versions. 显然,Ubuntu版本之间的解决方案不同。 Following worked for me on Ubuntu 13.10: 以下为Ubuntu 13.10工作:
sudo apt-get install nodejs-legacy
HTH HTH
Edit: Rule of thumb: 编辑: 经验法则:
If you have installed nodejs
but are missing the /usr/bin/node
binary, then also install nodejs-legacy
. 如果您已安装nodejs
但缺少/usr/bin/node
二进制文件,则还要安装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. 根据我的测试中,Ubuntu的17.10和上面已经有兼容性软链接/usr/bin/node
到位后nodejs
安装,这样nodejs-legacy
从这些版本缺少,因为它没有更多的需要。
#5楼
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. 至少在bash中直接运行并执行.js文件。
#6楼
Adding to @randunel's correct answer (can't yet comment on SO): 添加到@ randunel的正确答案(尚未对SO发表评论):
I also had to symlink /usr/local/bin/node to /usr/bin/nodejs as well. 我还必须将/ usr / local / bin / node符号链接到/ usr / bin / nodejs。
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
Apparently, this was overriding the /usr/bin/ node command. 显然,这会覆盖/ usr / bin / node命令。
No idea how that got set, but hope it helps someone else as it was a pain to figure out why the above wasn't working for me. 不知道如何设定,但希望它可以帮助别人,因为弄清楚为什么以上不适合我是一种痛苦。