Gem Bundle 慎用 `bundle clean --force`

lb563 · 2014年02月14日 · 最后由 lb563 回复于 2014年02月14日 · 4613 次阅读

昨天在使用 bundle 的时候 使用了命令:bundle clean --force

只见输出:

Remove Gem activerecord
Remove Gem xxx
Remove Gem xxx
Remove Gem xxx
Remove Gem xxx
Remove Gem xxx

果断ctrl + c 程序结束后。回到项目中 rake -T 输出:

lioooo:deploy lioooo$ rake -T
rake aborted!
cannot load such file -- active_record/deprecated_finders

查看 Gemfile 依赖的 gem 包:

source "http://ruby.taobao.org"

gem "colored", "1.2"
gem "activerecord", "3.2.3"
gem "logging", "1.8.1"
gem "pry", "0.9.10"
gem "capistrano", "2.9.0"
gem "capistrano_colors", "0.5.5"
gem "capistrano-ext", "1.2.1"
gem "rake-hooks", "1.2.3" #rake callback gems

再次回到项目根目录执行命令:bundle install 输出:

Using rake (10.0.3)
Using i18n (0.6.4)
Using multi_json (1.7.2)
Using activesupport (3.2.3)
Using builder (3.0.4)
Using activemodel (3.2.3)
Using arel (3.0.2)
Using tzinfo (0.3.37)
Using activerecord (3.2.3)
Using highline (1.6.15)
Using net-ssh (2.6.3)
Using net-scp (1.0.4)
Using net-sftp (2.0.5)
Using net-ssh-gateway (1.1.0)
Using capistrano (2.9.0)
Using capistrano-ext (1.2.1)
Using capistrano_colors (0.5.5)
Using coderay (1.0.9)
Using colored (1.2)
Using little-plugger (1.1.3)
Using logging (1.8.1)
Using method_source (0.8.1)
Using slop (3.3.3)
Using pry (0.9.10)
Using rake-hooks (1.2.3)
Using bundler (1.3.5)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

结束后执行命令 rake -T 输出:

lioooo:deploy lioooo$ rake -T
rake aborted!
cannot load such file -- active_record/deprecated_finders

同样的错误 !!!!!!!!!

执行命令 bundle show activerecord 输出

The gem activerecord has been deleted. It was installed at:
/usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3

提示 activerecord-3.2.3 已经被删除。果然 gem list activerecord 结果输出:

gem list activerecord

*** LOCAL GEMS ***

activerecord (4.0.2, 3.2.16, 3.2.14, 3.2.11, 3.2.8, 3.2.3, 3.2.2, 3.2.1, 3.2.0, 3.0.10, 2.3.11, 2.3.8)

于是奇怪的问题就出现了:bundle 提示 activerecord-3.2.3 已经被删除,但是gem list 却能找到该版本的activerecord

难道 gem list 有什么缓存信息?gem list 是列举出系统 gem env 目录中所有安装的 gem.

这个时候我需要做什么来挽救当前环境呢?

bundle update 

建议你更新一下试试

@mystery 还是同样的错误

bundle update
Fetching source index from http://ruby.taobao.org/
Resolving dependencies...
Installing rake (10.1.1)
Using i18n (0.6.9)
Using multi_json (1.8.4)
Using activesupport (3.2.3)
Using builder (3.0.4)
Using activemodel (3.2.3)
Using arel (3.0.3)
Using tzinfo (0.3.38)
Using activerecord (3.2.3)
Installing highline (1.6.20)
Installing net-ssh (2.8.0)
Using net-scp (1.1.2)
Using net-sftp (2.1.2)
Using net-ssh-gateway (1.2.0)
Using capistrano (2.9.0)
Using capistrano-ext (1.2.1)
Using capistrano_colors (0.5.5)
Using coderay (1.0.9)
Using colored (1.2)
Using little-plugger (1.1.3)
Using logging (1.8.1)
Using method_source (0.8.2)
Using slop (3.3.3)
Using pry (0.9.10)
Using rake-hooks (1.2.3)
Using bundler (1.3.5)
Your bundle is updated!
rake -T
rake aborted!
cannot load such file -- active_record/deprecated_finders

不过可以先把 "Gemfile.lock" 删除了,然后执行 bundle install

bundle install
Fetching source index from http://ruby.taobao.org/
Resolving dependencies.......
Installing rake (10.1.1)
Installing i18n (0.6.9)
Installing multi_json (1.8.4)
Installing activesupport (3.2.3)
Installing builder (3.0.4)
Installing activemodel (3.2.3)
Installing arel (3.0.3)
Installing tzinfo (0.3.38)
Installing activerecord (3.2.3)
Installing highline (1.6.20)
Installing net-ssh (2.8.0)
Installing net-scp (1.1.2)
Installing net-sftp (2.1.2)
Installing net-ssh-gateway (1.2.0)
Installing capistrano (2.9.0)
Installing capistrano-ext (1.2.1)
Installing capistrano_colors (0.5.5)
Installing coderay (1.0.9)
Installing colored (1.2)
Installing little-plugger (1.1.3)
Installing logging (1.8.1)
Installing method_source (0.8.2)
Installing slop (3.3.3)
Installing pry (0.9.10)
Installing rake-hooks (1.2.3)
Using bundler (1.3.5)
Your bundle is complete!
It was installed into /usr/local/Cellar/ruby/1.9.3-p125/lib/ruby/gems/1.9.1/cache

等执行完毕后,使用命令 bundle exec rake -T 就可以列举出 task

但是如果不用bundle exec的话还是有错误。这个我就比较疑惑了.难道 bundle install 不会把 gem 安装到 env 系统的目录中去?之前一直是这样安装的啊。

bundle exec 的作用就是用 Gemfile 里指定的 rake 版本 执行

#3 楼 @mystery 嗯。是这样的.我比较疑惑为什么不 bundler 没有把 gem 安装到 gem env中的 gem directory 中去。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号