I switched to ohmyzsh and curretly I have rbenv + .ruby-version file in repo
When I'm opening console in the shell I can see correct version of ruby
But doom emacs shows another version
looks like the same issue with fish shell as well
see the same version as in zsh/fish console
This is because you are launching emacs from your desktop environment which doesn't have the same environment variables as your shell. Emacs inherits it's environment variables from wherever it's launched. As an experiment try opening a zsh (or fish) shell with the correct rbenv settings and then launching emacs from the shell. Does it have the correct version now? If it does here's one way you get those variables into instances launched from your desktop:
Get the following package: (package! exec-path-from-shell)
and then configure it to grab what you need:
(when (memq window-system '(mac ns x))
(require 'exec-path-from-shell)
(setq-default exec-path-from-shell-shell-name "/usr/bin/zsh")
(exec-path-from-shell-copy-env "RUST_SRC_PATH")
(exec-path-from-shell-initialize))
This will copy the PATH variable from zsh and it will also copy "RUST_SRC_PATH" from zsh. Hopefully you can figure out which variables you need.
While exec-path-from-shell will work, if you're on mac, Doom is already using it.
You can tell it to pick up more envvars with the set-env! function. E.g.
(after! go-mode
(set-env! "GOPATH" "GOROOT"))
However, if you aren't on Mac, or if Doom still isn't picking up those envvars, a common reason for that is those variables are configured in ~/.zshrc (read in interactive sessions) rather than ~/.zshenv (non-interactive sessions). App launchers tend to spawn processes from a non-interactive session.
For rbenv, specifically, I believe the best way would be to move your rbenv init to ~/.zshenv. Same goes for any envvars you think should be visible globally.
If that is too slow, try rbenv init - --no-rehash instead.
Here is what I use to ensure it has minimal impact on shell init time:
function _cache {
local cache_dir="${XDG_CACHE_HOME:-~/.local/share}/${SHELL##*/}"
local cache="$cache_dir/$1"
if [[ ! -f $cache || ! -s $cache ]]; then
echo "Caching $1"
mkdir -p $cache_dir
"$@" >$cache
fi
source $cache
}
_cache rbenv init - --no-rehash
@hlissner btw, described case happens on Mac, however I switched to asdf and didn't test it yet
for some reason, it still requires rvm
rspec-compile: Symbol’s function definition is void: rvm-activate-corresponding-ruby
and I still didn't get why by default it execute fish instead of zsh ?
I fixed the above error with the following config
(after! rspec-mode
(setq rspec-use-rvm nil))
@idoo Sorry for the late reply. Does @eltone's snippet work for you?
@hlissner not really :( I still have wrong ruby version :(
I am also having the problem.
Most helpful comment
While exec-path-from-shell will work, if you're on mac, Doom is already using it.
You can tell it to pick up more envvars with the
set-env!function. E.g.However, if you aren't on Mac, or if Doom still isn't picking up those envvars, a common reason for that is those variables are configured in
~/.zshrc(read in interactive sessions) rather than~/.zshenv(non-interactive sessions). App launchers tend to spawn processes from a non-interactive session.For rbenv, specifically, I believe the best way would be to move your
rbenv initto~/.zshenv. Same goes for any envvars you think should be visible globally.If that is too slow, try
rbenv init - --no-rehashinstead.Here is what I use to ensure it has minimal impact on shell init time: