I'm using the exec-path-from-shell package to copy my environment variables, including PATH. But shell-command (M-! which ruby RET) only finds the system ruby, not my user-local rvm ruby.

Similarly, when I switch to a project using projectile and invoke projectile-compile-project (C-p c), the usual compilation command to build my website doesn't work, e.g.: "bundle exec nanoc compile"

It tries to use the system ruby:

-*- mode: compilation; default-directory: "~/Sites/christiantietze.de/" -*-
Compilation started at Sun Aug  2 12:23:46

bundle exec nanoc compile
Traceback (most recent call last):
    2: from /usr/bin/bundle:23:in `<main>'
    1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /Users/ctm/Sites/christiantietze.de/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.1.4`

Compilation exited abnormally with code 1 at Sun Aug  2 12:23:46

The only way I found to use rvm from within emacs to do anything at all for me is to change the shell command to:

rvm default do bundle exec nanoc compile

So the rvm function is available and loaded in the shell; it's just that the PATH doesn't appear to be updated.

  • which ruby within shell returns /usr/bin/ruby
  • which ruby within eshell correctly returns /Users/ctm/.rvm/rubies/ruby-2.7.1/bin/ruby
  • (getenv "PATH") leads with "/Users/ctm/.rvm/rubies/ruby-2.7.1/bin", so the emacs environment should work
  • (getenv "SHELL") and shell-file-name report "/usr/local/bin/zsh" 👍 (explicit-shell-file-name is nil, but changing it to the same path didn't help, either)

Is there a way to make the regular emacs shell commands (and thus projectile) aware of the stuff that eshell knows?

Your Answer

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

Browse other questions tagged or ask your own question.