23

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?

Erel Segal-Halevi
  • 33,955
  • 36
  • 114
  • 183
  • Does this answer your question Erel? – Mike Biglan MS Oct 08 '15 at 17:59
  • Duplicate of these: http://stackoverflow.com/questions/20921427/nodejs-gone-after-linux-reboot http://stackoverflow.com/questions/24585261/nvm-keeps-forgetting-node-in-new-terminal-session – Tyler Jun 22 '16 at 16:40

1 Answers1

22

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.

Mike Biglan MS
  • 1,822
  • 1
  • 20
  • 20