Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为什么我的环境要求我运行bundle exec?_Ruby On Rails_Ruby On Rails 3_Rake_Gemfile - Fatal编程技术网

Ruby on rails 为什么我的环境要求我运行bundle exec?

Ruby on rails 为什么我的环境要求我运行bundle exec?,ruby-on-rails,ruby-on-rails-3,rake,gemfile,Ruby On Rails,Ruby On Rails 3,Rake,Gemfile,每当我运行rake命令(即,rake路由)时,我都会遇到以下错误: You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this. 如果我运行bundle exec rake routes,它会工作 我希望能够简单地rake routes,而不必运行bundle exec rake routes 我研究了其他有类似错误的问题,并尝试了

每当我运行rake命令(即,
rake路由
)时,我都会遇到以下错误:

You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.
如果我运行
bundle exec rake routes
,它会工作

我希望能够简单地
rake routes
,而不必运行
bundle exec rake routes

我研究了其他有类似错误的问题,并尝试了各种解决方案(比如运行
bundle update
),但都无济于事

另外,在我的
gemfile
中,我指定了
gem'rake',0.9.2'

有什么建议吗?

尝试执行:

gem list

您可能会看到为rake安装了几个版本。顺便说一下,
bundle exec
是在Rails应用程序上下文中执行代码的正确方法。因此,如果您使用rvm,您可以使用别名键入更少的内容。

。你可以试试下面的

rvm gem list

正如@lucapete所说,您可能有多个版本的rake。假设您确实想要使用0.9.2,您可以删除0.9.2.2版本以消除警告,然后运行bundle install以确保您拥有所有适合您想要的版本的gem版本(在您的情况下为0.9.2,在下面的我的示例中为0.8.7)

以下是步骤:

$ gem list

*** LOCAL GEMS ***

...
rake (0.9.2.2, 0.8.7)
...

$ gem uninstall rake

Select gem to uninstall:
 1. rake-0.8.7
 2. rake-0.9.2.2
 3. All versions
> 2

You have requested to uninstall the gem:
        rake-0.9.2.2
addressable-2.2.6 depends on [rake (>= 0.7.3)]
...
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  Y
Successfully uninstalled rake-0.9.2.2
INFO:  gem "0.9.2.2" is not installed

$ bundle install

如果GEM文件中的某些GEM要求安装旧版本的Rake,您可能会看到此消息。也许你已经更新了rake。你经常可以通过更新你的gems来修复它。运行:

bundle update

这将使用GEM文件中最新的GEM更新您的包。这可能会修复rake的不兼容性。

您也可以使用
导出RUBYOPT=-rbundler/setup
启动shell会话,这就是
bundle exec
所做的一切。这给了我:ruby:没有这样的文件要加载--bundler/setup(LoadError)快速更新。最近,RailsTutorial就需要使用
bundle exec
“如第3.2.1节所述,通常有必要在命令(如rake或rspec)前面加上bundle exec前缀,以便程序在gem文件指定的确切gem环境中运行。(出于技术原因,唯一的例外是rails命令本身。)“此外,“只要RVM的版本号为1.11.x或更高,安装的gems将在适当的绑定器环境中自动执行”,因此不需要
bundle exec
prefix.link来解释: