Reputation: 36753
I installed NVM on an ubuntu machine, but, when I put it in the crontab for execution during reboot:
@reboot nvm use 0;
it didn't work, and I got a mail from the cron daemon, saying:
/bin/sh: 1: nvm: not found
So, I thought this a path problem, and tried to find where NVM is installed. To my surprise, I got empty results:
root@vps-1145280-18735:~# which nvm
root@vps-1145280-18735:~#
But, NVM itself does work, even after reboot:
root@vps-1145280-18735:~# nvm
Node Version Manager
...
This is very strange - how can it be that the system finds the nvm program, when the "which nvm" is empty?!
And, more important - what should I do in order to have the cron program find NVM during startup?
Upvotes: 25
Views: 5296
Reputation: 1882
The nvm
command is not a file but rather a shell function.
The source ~/.nvm/nvm.sh
adds these functions to your current shell. And because these commands are not files, they don't show up when you which nvm
.
Looking in the .nvm/nvm.sh
file, you can see a nvm() {...} function defined that provides that functionality.
Cron is likely using as different user, and that user needs to have source ~/.nvm/nvm.sh
added to its shell context before running.
Upvotes: 25