Using Spring, direnv, and RVM

If you’re using the Spring gem, then you should have your /bin directory first in your path.

Using a .envrc file

Why

It’s critical that you’re actually using the spring-ified commands. The bin stubs in the bin directory have been modified to use Spring. However, it’s super easy to accidentally not use them, as your path probably has the binstub in the gems directory in your path. Even running spring status is typically incorrect (and slow). Run the command which -a spring and you’ll probably see that spring comes from your gem directory. You can either always remember to prefix the commands with bin/ or you can create a .envrc file.

For a quick test, run time rake routes > /dev/null twice. If spring is working correctly, then the second run is less than a second usually.

Also, which <command> and type <command>, like which rspec, are useful to see if your .envrc is being used.

How

Create a file at the top of the project called .envrc containing:

PATH_add bin

Save the file and run the command direnv allow

For more info on .envrc, see https://direnv.net/.

IMPORTANT for RVM users

The PATH_add bin doesn’t work unless you add this line to your ~/.rvmrc:

rvm_project_rvmrc=0

Without that line, RVM will sneak in the last path change to put it’s path before the /bin directory! So that’s the secret sauce with RVM.