Rails execjs cannot find node when using NVM

I use NVM to manage my versions of Node.js on the system, and since I installed it, applications on rails stop working.

ExecJS cannot find node runtime by error:

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

What steps are needed to make NVM play well with ExecJS?

+6
source share
2 answers

Just stumbled upon this problem myself. In principle, NVM is good because it allows you to install and run several different versions of Node on the same computer without sudo privileges. Since there are several versions, it does not automatically download the version for your shell for you, you must specify which one you want to use. nvm use default loads the default Node environment (and not the 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 , view this issue for more information.

+2
source

In our case, we start Rails as a "normal" user using the command

 bundle exec puma -C config/puma.rb 

As long as you have the "default" node nvm via nvm , you should be fine.

 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 

The next time you log in as a user, which node should specify the path in nvm :

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

Similarly, Rails will get the node that will be used.

+1
source

Source: https://habr.com/ru/post/956157/


All Articles