Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"which nvm" is gone

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?

like image 701
Erel Segal-Halevi Avatar asked Oct 02 '13 07:10

Erel Segal-Halevi


People also ask

What is the current version of NVM?

For now, it is the April 28, 2022 version. Step 3: Locate the installer on your computer and open it. Follow the installation wizard to install it. Step 4: Open up PowerShell or Command Prompt and run nvm -v to confirm the installation.

How do I change NVM version?

For switching to different versions that are already installed you can use the following commands for different scenarios: nvm use node #uses latest Node. js version available on server. nvm use --lts #This will switch to the latest LTS version nvm use 14.15.

How do I know if Windows NVM is installed?

Then to check if nvm is properly installed, open a new command prompt terminal and type nvm . Once it is verified that it is installed you can move on to the next step. The version can be a NodeJS version or "latest" (for the latest stable version).


1 Answers

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.

like image 97
Mike Biglan MS Avatar answered Sep 27 '22 18:09

Mike Biglan MS