how do you activate or set the default rake?

2019-04-06 03:21发布

问题:

I have seen many

You have already activated rake 0.9.x, but your Gemfile requires rake 0.x.x

errors.

Of course, they can be solved (temporarily or always) by some methods like the following.

bundle exec rake

The method above works but you always have to type bundle exec.

It can also be solved by

bundle update

But bundle update also updates your other gems.

Some say it can be solved by

gem uninstall unwanted_rake_version

Yes, the unwanted rake can be installed but it is still marked as activated thus, still giving the error.

One solution would be to explicitly specify the rake version in your Gemfile but, that is not the question. It is on how to set the default rake version, or activate that specific version in rvm or other types of ruby installations?

回答1:

The newer versions of rake can be activated by supplying an optional first argument, that is the gem version.

$ rake 0.9.2

Alternatively, if you have an older version of rake you can update the rake script manually to include this parameter (or specify any specific version you want).

The rake script usually lives in /usr/bin/rake (or ~/.rvm/gems/ruby-#{ruby-name}/rake if using rvm). And dictates the version of them gem to load before parsing paramaters.

It looks like this on my system.

$ cat ~/.rvm/gems/ruby-1.9.2-p180/bin/rake

#!/home/tomcat/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'rake', version
load Gem.bin_path('rake', 'rake', version)

The important bit is gem 'rake', version changing version will force rake to a specific version system/rvm wide.

For more info, Katz' article explains nicely how binaries run under rubygems



回答2:

When I get that error, its usually a result of working between projects that depend on different versions of rake. An easy fix is

gem uninstall rake

And then in your project directory (assuming you're working with Bundler) simply

bundle


回答3:

I always uninstall rake first, command like this:

gem uninstall rake -v=version

then install another version

gem install rake -v=version