- macOS Cataline 10.15.1
- RubyMine 2019.2.4
- Rbenv to manage Ruby version
Steps Leading Up To Problem:
- Installed rbenv
- Installed Ruby version 2.4.1 (wanted an old version)
- Installed Rails 5.1.3 gem (again, I wanted this version)
- Performed rbenv rehash
- Set rbenv global to 2.4.1
- Configured RubyMine to use rbenv version of Ruby
- Create new application using RubyMine interface.
- From the Run Anything prompt, I can run rails server, and it works fine. However, if I run rails version, it tells me that rails is not installed.
- If I use rbenv in the RubyMine Terminal to switch to the system version (which doesn't have rails), I also get an error that rails doesn't exist. If I switch the rbenv shell to 2.4.1 in the Terminal, rails is detected.
- I have a feeling that the Run Anything prompt is feeding commands to a shell that hasn't read the rbenv environment variables and therefore it's not detecting the rbenv rails shim (command) that is being detected by the Terminal
- This is confirmed by checking the PATH in the Terminals that work, vs Run Anything's PATH. The Terminal PATHs have .rbenv paths at the start, and Run Anything has the .rbenv paths at the end of its PATH
- If I run eval "$(rbenv init -)" && env, then I get the correct PATH
How can I get Run Anything to detect the rails gem installed by rbenv?
The issue was in which configuration file for zsh was being loading. Commands run via Run Anything are run via a non-interactive login shell.
Can confirm by running
if [[ -o login ]]; then; print yes; else; print no; fi
if [[ -o interactive ]]; then; print yes; else; print no; fi
in Run Anything.
Zsh loads config files in the follow order (talking about user configs in the home directory):
- .zprofile (for login shells) <- rbenv eval moved here
- .zshrc (for interactive shells) <- rbenv eval initially here
- .zlogin (for login shells)
My rbenv eval (the command while allows the shell to see rails) was in zshrc (thought that this was the right place, ex-bash user). But since Run Anything is a non-interactive shell, that config file was not getting loaded.
Solution: If you are using rbenv to manage your Ruby version, then make sure it is place in .zprofile so that it works in Run Anything.
Don't know what to do with this post, will keep it here if anyone else experiences this problem, mods are free to delete.