简体   繁体   中英

Shell script to switch between MRI and jruby

Working on a project which uses jRuby, but locally when I work I often use MRI because it's faster.

Now switching between to is a major annoyance, this is how I switch from jruby to MRI:

rvm use ruby-2.1.5
sed -i.bak 3s/.*/ruby" '2.1.5'"/ Gemfile 

Which replaces my Gemfile and specifies the right version of ruby. Now I wanted to create two executables from bin/ folder of my rails project, one called mri and another one jruby so I could switch back and forth between the two using a single command, and so that everyone who work in a team can use the same.

Problem with this is that, when the shell executes, the RVM doesn't change the ruby version in my current session. So naturally I get this message :

Your Ruby version is 2.0.0, but your Gemfile specified 2.1.5

  1. Is this a good approach to what I'm trying to do? pretty sure I'm not the first person trying this

  2. Do you already have something that works for you?

As the comments pointed out, you need to re-source the rvm scripts. You probably could just source ~/.bash_profile or ~/.bash_rc again, as they should be sourced there.

That being said, I haven't had this problem with rbenv , but I only swap between MRI versions. There is also a spec for a .ruby-version file see here that both RVM and rbenv honor.

For bundling bin stubs you can specify a bin path with bundle binstubs --path mri-bin .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM