3

I've got Node installed using NVM, and Emacs (v25.2.1) isn't able to find Node. When I run M-: (executable-find "node") I get back nil.

However, when I run M-: (executable-find "cat") I get "/bin/cat". I assume the difference is due to my use of NVM.

How do I get Emacs to find Node when I've got Node installed using NVM?

Incidental technical details:

My Emacs was installed using MacPorts (using the emacs-app package that installs to the Mac Applications folder for a GUI experience), and I've got the following lines in my ~/.bashrc:

export NVM_DIR="/Users/fred/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

My ~/.bash_profile contains source ~/.bashrc.

I'm not sure if this is relevant to the problem, but I should mention that when I open M-x eshell, I get the following when trying to run Node:

$ node
node: command not found

However, I am able to run Node through M-x shell.

I did have limited success installing the emacs package (as opposed to the emacs-app package) from MacPorts. Using the Emacs from the emacs package (which installs to /opt/local/bin/emacs), I was able to evaluate in the scratch buffer:

(executable-find "node")

And successfully got the path to node. However, this same lisp expression evaluated in the Emacs from the emacs-app package yielded nil. This doesn't help me much, because I want to use the emacs from emacs-app, because it's the Emacs with the graphical interface for Mac, as I understand it.

I want to continue using NVM, please.

  • The doc-string for executable-find states: "Search for COMMAND in ‘exec-path’ and return the absolute file name. Return nil if COMMAND is not found anywhere in ‘exec-path’." You can inspect the exec-path with C-h v or M-x describe-variable. If the path containing the node executable is not there, then you will be one step closer to troubleshooting the issue. – lawlist Jul 15 '17 at 23:03
  • Most likely, your .bashrc code has no effect because there's no bash involved (i.e. you start Emacs from the GUI which has not executed a bash shell). – Stefan Jul 16 '17 at 1:18
  • I run my emacs in the terminal. And my emacs shell sees the system node, rather than the nvm node. Seems very silly. I guess nvm is doing something sneaky. rvm works fine. The nvm default is set to the node version I want. But nvm just doesn't play nice. – nroose Sep 27 '19 at 22:59
7

Best solution:

Install exec-path-from-shell. From the documentation, after calling (package-initialize), add the following to your .emacs file:

(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

Another solution:

Add the following to your .emacs file:

(setq exec-path (append exec-path '("~/.nvm/versions/node/v6.3.0/bin")))

Your version number in the string above may differ. I don't like this solution as much as the "best solution," because it must be manually updated to keep the emacs path synchronized with the system path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.