Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails execjs can't find node when using NVM

I'm using NVM to manage my Node.js versions on the system, and since I installed it my rails apps stop working.

ExecJS can't seem to find node runtime, giving the error:

Node.js (V8) runtime is not available on this system (ExecJS::RuntimeUnavailable)

what actions are needed to make NVM play well with ExecJS?

like image 590
SnirD Avatar asked Oct 17 '13 10:10

SnirD


People also ask

Can I install NVM with node already installed?

You can install and use NVM regardless of whether you have installed Node already. NVM alters path variables to select different versions of Node, so it works with pre-existing installations. Install NVM using either curl or wget .

How do I enable NVM?

nvm use node OR nvm use 11.10. This command will set the version of Node. js running locally to the latest version downloaded if you just type nvm use node , or the version specified if you append the command with the version number nvm use --version e.g. nvm use 8.15.

Does node come with NVM?

npm comes with Node. js so if you have node installed ( node --version ) you most likely have npm installed as well. You don't need nvm unless you you want to keep multiple versions of Node. js installed on your system or if you'd like to upgrade your current version.


2 Answers

Just ran into this issue myself. Basically, NVM is nice because it allows you to install and run multiple different versions of Node on one computer without sudo privileges. Since there are multiple versions, it does not automatically load a version in your shell for you, you have to specify which one you want to use. nvm use default loads the default Node environment (instead of default you can specify a specific version) into the current shell, but this will stop working when the shell is closed. To make the change permanent, use nvm alias default node, check out this issue for more info.

like image 102
James L. Avatar answered Oct 16 '22 01:10

James L.


In our case, we're running Rails as a "regular" user with the command

bundle exec puma -C config/puma.rb

As long as you have a "default" node set through nvm, you should be okay.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
nvm install v0.12.7
nvm alias default v0.12.7

Next time you log in as that user, which node should indicate the path under nvm:

~/.nvm/versions/node/v0.12.7/bin/node

Likewise, Rails will pick up that node as the one to use.

like image 30
bonh Avatar answered Oct 16 '22 01:10

bonh