暈死居然花了一個多小時~下來來個詳細版本的。。
/bin/sh: node: command not found
如果遇到這個問題,這篇教程簡直就是爲你量身定做!!!
首先你得有nodejs在電腦裏,沒有的話就去nodejs.org下載
1.去github下載nodejs:
https://github.com/tanepiper/SublimeText-Nodejs
2.解壓,改名爲Nodejs 此處注意大小寫
3.SublimteText3 --> Preferences--> Browse Packages 把解壓好的文件放進去
4.打開bash shell, 輸入指令
which node
和which npm
得到絕對路徑,
比如我的就是
/usr/local/bin/node 和 /usr/local/bin/npm
5.打開Nodejs(剛纔解壓並且放好的那個文件),找到 Nodejs.sublime-settings,用sublime打開,如下
{
// save before running commands
"save_first": true,
// if present, use this command instead of plain "node"
// e.g. "/usr/bin/node" or "C:\bin\node.exe"
"node_command": "/usr/local/bin/node",
// Same for NPM command
"npm_command": "/usr/local/bin/npm",
// as 'NODE_PATH' environment variable for node runtime
"node_path": false,
"expert_mode": false,
"ouput_to_new_tab": false
}
把false改爲自己的路徑, false --> "/usr/local/bin/node"
6.打開Nodejs(剛纔解壓並且放好的那個文件),打開Nodejs.sublime-build,改爲如下:
{
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf-8",
"windows":
{
"cmd": ["taskkill /F /IM node.exe & node", "$file"]
},
"linux":
{
"cmd": ["killall node; node", "$file"]
},
"osx":
{
"cmd": ["/usr/local/bin/node; node $file"]
}
}
7. 打開一個新的文件,敲進console.log('hello world') 然後control+r就運行了