'/usr/bin/env: node: No such file or directory' error when running `gulp` via cron job
Created by: romellem
This is mostly to add some documentation since I am unable to comment on #436 (closed).
Basically, if you have a gulp task, say build, that you normally run via
gulp build
And you are trying to add that to a cron job, you may try something like this: while ssh'd, you run
which gulp
To get a full path for the global gulp. I get back the path /usr/local/bin/gulp (yours might differ).
Anyways, once you have this path, you might decide "run this gulp task every five minutes," which would be setup as the following cron job:
*/5 * * * * cd /your/dir/to/run/in && /usr/local/bin/gulp build
However, you will see in the cron logs that you get this error:
/usr/bin/env: node: No such file or directory
#436 directs you to try the following:
I also did face same issue. This is how I solved it. sudo ln -s /usr/bin/nodejs /usr/bin/node
just in case someone came here looking for solution to this problem.
However, that assumes that /usr/bin/nodejs is the actual path to your node binary.
Really what you want to do is run which node, and whatever that path is, is what you want to link to.
In my case, running which node shows:
/usr/local/bin/node
So, first I ended up running
sudo ln -s /usr/local/bin/node /usr/bin/node
And only after creating that symbolic link did my original cron job execute.
TL;DR:
Run the following if you are having trouble running a gulp task from cron:
sudo ln -s $(which node) /usr/bin/node