...without uninstalling the latest version.
…不卸载最新版本。
I'm working on a project that uses Bundler 1.10, but I use Bundler 1.11 for all my other projects. Since this project is on 1.10, whenever I run any bundle
commands, my Gemfile.lock
changes due to the different formatting introduced by Bundler 1.11.
我正在做一个使用Bundler 1.10的项目,但是我使用Bundler 1.11来完成其他项目。因为这个项目在1.10上,所以无论何时运行任何bundle命令,我的Gemfile都会运行。由于Bundler 1.11引入的不同格式而导致的锁更改。
The only solution I've found so far is running all my commands like so:
到目前为止,我发现的唯一解决方案是像这样运行我的所有命令:
bundle _1.10.6_ [command]
(from this answer here: https://*.com/a/4373478/1612744)
(答案如下:https://*.com/a/4373478/1612744)
Is there a better way? I'm using rbenv, not rvm.
有更好的方法吗?我用的是rbenv,不是rvm。
2 个解决方案
#1
4
You could use the rbenv-gemset plugin. Since an older version of a gem in an rbenv gemset doesn't override a newer version in the default gemset, you'd need to install bundler for each project, which is rather cumbersome.
你可以使用rbenv-gemset插件。由于rbenv gemset中的旧版本不会覆盖默认gemset中的新版本,因此需要为每个项目安装bundler,这相当麻烦。
- Install the plugin (
cd ~/.rbenv/plugins; git clone git://github.com/jf/rbenv-gemset.git
) OR, if you use homebrew,brew install rbenv-gemset
- 安装插件(cd ~/.rbenv/插件);或者,如果你使用homebrew, brew安装rbenv-gemset。
gem uninstall -xI bundler
- 宝石卸载*打包机
- For each project that can use bundler 1.11,
-
cd
to the project - cd到项目
-
echo bundler-1.11 > .rbenv-gemsets
("bundler-1.11" is the name of the gemset) - > .rbenv-gemsets(“bundler-1.11”是gemset的名字)
-
- 对于可以使用bundler 1.11的每个项目,cd到项目echo bundler-1.11 > .rbenv-gemsets(“bundler-1.11”是gemset的名字)
- In one of those projects,
gem install bundler
to get the current version, 1.11.* - 在其中一个项目中,gem安装bundler以获得当前版本1.11.*
- For the project that needs bundler 1.10,
-
cd
to the project - cd到项目
-
echo bundler-1.10 > .rbenv-gemsets
("bundler-1.10" is the name of the gemset) - echo bundler-1.10 > .rbenv-gemsets(“bundler-1.10”是gemset的名字)
gem install bundler -v 1.10.6
- gem安装bundler - v1.10.6。
-
- 对于需要bundler 1.10的项目,cd到项目echo bundler-1.10 > .rbenv-gemsets(“bundler-1.10”是gemset的名称)gem安装bundler- v1.10.6。
#2
2
I ended up solving this with an alias and a bash function. In my ~/.bashrc
, I added this:
最后我用一个别名和一个bash函数解决了这个问题。在我的~ /。bashrc,(我说的是:
versioned_bundle() {
version_file=${PWD}/.bundle/version
if [[ -r $version_file ]]; then
version=$(<$version_file)
bundle _${version}_ "$@"
else
bundle "$@"
fi
}
alias bundle=versioned_bundle
As you can guess from the code, I also added a version
file to the .bundle/
directory in my project. That file's contents:
您可以从代码中猜到,我还向项目中的.bundle/目录添加了一个版本文件。该文件的内容:
1.10.6
Whenever I run bundle
, my shell checks for a version file in the current directory, and if it finds it, runs that version of bundle.
每当我运行bundle时,我的shell检查当前目录中的版本文件,如果它找到了,就运行该版本的bundle。
$ cd project-with-old-bundle-version
$ bundle --version
1.10.6
$ cd anywhere-else
$ bundle --version
1.11.2
#1
4
You could use the rbenv-gemset plugin. Since an older version of a gem in an rbenv gemset doesn't override a newer version in the default gemset, you'd need to install bundler for each project, which is rather cumbersome.
你可以使用rbenv-gemset插件。由于rbenv gemset中的旧版本不会覆盖默认gemset中的新版本,因此需要为每个项目安装bundler,这相当麻烦。
- Install the plugin (
cd ~/.rbenv/plugins; git clone git://github.com/jf/rbenv-gemset.git
) OR, if you use homebrew,brew install rbenv-gemset
- 安装插件(cd ~/.rbenv/插件);或者,如果你使用homebrew, brew安装rbenv-gemset。
gem uninstall -xI bundler
- 宝石卸载*打包机
- For each project that can use bundler 1.11,
-
cd
to the project - cd到项目
-
echo bundler-1.11 > .rbenv-gemsets
("bundler-1.11" is the name of the gemset) - > .rbenv-gemsets(“bundler-1.11”是gemset的名字)
-
- 对于可以使用bundler 1.11的每个项目,cd到项目echo bundler-1.11 > .rbenv-gemsets(“bundler-1.11”是gemset的名字)
- In one of those projects,
gem install bundler
to get the current version, 1.11.* - 在其中一个项目中,gem安装bundler以获得当前版本1.11.*
- For the project that needs bundler 1.10,
-
cd
to the project - cd到项目
-
echo bundler-1.10 > .rbenv-gemsets
("bundler-1.10" is the name of the gemset) - echo bundler-1.10 > .rbenv-gemsets(“bundler-1.10”是gemset的名字)
gem install bundler -v 1.10.6
- gem安装bundler - v1.10.6。
-
- 对于需要bundler 1.10的项目,cd到项目echo bundler-1.10 > .rbenv-gemsets(“bundler-1.10”是gemset的名称)gem安装bundler- v1.10.6。
#2
2
I ended up solving this with an alias and a bash function. In my ~/.bashrc
, I added this:
最后我用一个别名和一个bash函数解决了这个问题。在我的~ /。bashrc,(我说的是:
versioned_bundle() {
version_file=${PWD}/.bundle/version
if [[ -r $version_file ]]; then
version=$(<$version_file)
bundle _${version}_ "$@"
else
bundle "$@"
fi
}
alias bundle=versioned_bundle
As you can guess from the code, I also added a version
file to the .bundle/
directory in my project. That file's contents:
您可以从代码中猜到,我还向项目中的.bundle/目录添加了一个版本文件。该文件的内容:
1.10.6
Whenever I run bundle
, my shell checks for a version file in the current directory, and if it finds it, runs that version of bundle.
每当我运行bundle时,我的shell检查当前目录中的版本文件,如果它找到了,就运行该版本的bundle。
$ cd project-with-old-bundle-version
$ bundle --version
1.10.6
$ cd anywhere-else
$ bundle --version
1.11.2