简体   繁体   English

Shell脚本在MRI和jruby之间切换

[英]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. 在一个使用jRuby的项目上工作,但在我工作的时候,我经常使用MRI,因为它更快。

Now switching between to is a major annoyance, this is how I switch from jruby to MRI: 现在切换到是一个主要的烦恼,这是我如何从jruby切换到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. 这取代了我的Gemfile并指定了正确版本的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. 现在我想从我的rails项目的bin/文件夹中创建两个可执行文件,一个名为mri ,另一个名为jruby因此我可以使用一个命令在两者之间来回切换,以便团队中的每个人都可以使用相同。

Problem with this is that, when the shell executes, the RVM doesn't change the ruby version in my current session. 问题在于,当shell执行时,RVM不会更改当前会话中的ruby版本。 So naturally I get this message : 所以我自然得到这样的信息:

Your Ruby version is 2.0.0, but your Gemfile specified 2.1.5 您的Ruby版本是2.0.0,但您的Gemfile指定为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. 正如评论所指出的,您需要重新获取rvm脚本。 You probably could just source ~/.bash_profile or ~/.bash_rc again, as they should be sourced there. 您可能只~/.bash_rc再次提供~/.bash_profile~/.bash_rc ,因为它们应该来源。

That being said, I haven't had this problem with rbenv , but I only swap between MRI versions. 话虽这么说,我没有用rbenv这个问题,但我只在MRI版本之间交换。 There is also a spec for a .ruby-version file see here that both RVM and rbenv honor. 还有一个.ruby-version文件的规范, 这里看到RVM和rbenv荣誉。

For bundling bin stubs you can specify a bin path with bundle binstubs --path mri-bin . 对于捆绑bin存根,您可以使用bundle binstubs --path mri-bin 指定bin路径 bundle binstubs --path mri-bin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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