Using bundle exec may solve this? - ruby

Here is my Gemfile
source :rubygems
gem 'rake', '0.9.2.2'
gem 'sinatra'
gem 'activerecord', '3.0.9'
gem 'pg', '~> 0.12.2'
gem 'logger'
gem 'nokogiri'
group :development, :test do
gem 'rack-test'
gem 'ruby-debug19'
gem 'sqlite3'
end
I run rake console which works in other projects and now I get this message:
You have already activated activesupport 3.1.3, but your Gemfile requires activesupport 3.0.9. Using bundle exec may solve this.
How do I use `bundle exec to solve this? What does it mean?

To stop using bundle exec rake you can run bundle clean --force. This command will update your Gemfile.lock.

You can run bundle exec rake console which means that the command (in this case rake console) will be locked to the specific gems listed in your Gemfile.

rubygems-bundler solves this. Run the following commands:
$ gem install rubygems-bundler
$ $ gem regenerate_binstubs
Then try your bundle again.

You can check to make sure that you include rake in your Gemfile. If it's not, add it, and specify the version "you already activated".
or you can just update it on your local like
bundle update rake
I hope that this helps

Related

bundle install: 'minitest/autorun x64-mingw32' not in Gemfile

When trying to run bundle install on i receive the following exception:
$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Could not find gem 'minitest/autorun x64-mingw32' in any of the gem sources
listed in your Gemfile.
I was originally trying to run bundle exec rake, which suggests the same issue with gem 'minitest/autorun x64-mingw32'. Running them with rake test works fine; hence, I think I've done something wrong with bundler related to my OS (windows 7 x64). The install works properly without this package. I also tried using unit/test with the same result.
Ruby version is 2.4.4.
Gemfile:
source "https://rubygems.org"
gemspec
gem 'json', '~> 2.1.0', '>= 2.0.4'
gem 'addressable', '~> 2.5.2', '>= 2.5.2'
gem 'mongo', '~> 2.5.1', '>= 2.5.1'
group :test do
gem 'rake'
gem 'minitest/autorun'
end
Do I need to specify the platform or some other variable so that bundle looks for the right version of the gem on rubygems?
Any help would be much appreciated.

Is there a way to "gem install" to only the development environment, or test?

Using gem install, how can I add a gem to only one particular environment, like development or test or production? As seen below:
group :development do
gem 'web-console', '>= 3.3.0'
end
You can't do this via gem as the Gemfile is used by Bundler. However, since Bundler version 1.15.0 you can use bundle add:
bundle add web-console --group development
This will then add the following line to your Gemfile:
gem "web-console", "~> 3.6", :group => [:development]

How to install gems from Gemfile?

I want to add code coverage to my project and sign up coveralls.io and create Gemfile with:
gem 'coveralls', require: false
but how can I install the gem from Gemfile?
run the command bundle install in your shell, once you have your Gemfile created.
This command will look your Gemfile and install the relevant Gems on the indicated versions.
The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.
Your can create a Gemfile just by typing bundle init in your shell
I add a Gemfile example for your reference:
source "https://rubygems.org" # where gems will be downloaded from
ruby "2.2.3" # ruby version, change for the one you use
gem "sinatra"
gem "sinatra-flash"
gem "sinatra-partial"
gem "bcrypt"
gem "dm-validations"
gem "dm-transactions"
gem "data_mapper"
gem "dm-postgres-adapter"
gem "pg"
gem "database_cleaner"
group :test do # you can make groups for test, development, production..
gem "rspec"
gem "capybara"
gem "rspec-sinatra"
gem "cucumber"
gem "coveralls", require: false
end
First install bundler if you don't have it
gem install bundler or sudo gem install bundler if you don't have the required permissions. Bundler is a gem that manages gem dependencies.
then you can follow the above instruction for creating the gemfile, after which you can issue the command
bundle install

Bundle exec rake db:migrate does not work (and neither does rake db:migrate), Ubuntu

I am running a Rails 3 app on Ubuntu (EC2), I have rake locked at version 0.8.7 and when I do rake db:migrate I get the usual:
You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.8.7. Using bundle exec may solve this.
However when I do bundle exec rake db:migrate, I get the same response..
??
There are a couple of things that you can try:
Upgrade Ruby to 1.9.3 which will provide Rake 0.9.2.2
Add this to your Gemfile gem 'rake' , '>= 0.9.2' and run bundle update again.
Worst case, delete your Gemfile.lock and regenerate it again using bundle install

Missing gem when running rake

I'm using rbenv with Ruby 1.9.2-p290, Rails 3.1, and the database is MySQL.
When I try
rake db:create
I get the following error:
Could not find multi_json-1.0.3 in any of the sources
I've also tried bundle exec rake db:create.
My GemFile looks like this:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'mysql2'
gem 'json'
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
gem 'jquery-rails'
Quite old, but in case anyone else comes across this and is looking for the real answer: upgrade your bundler gem.
For me didn't work neither smathy and kalleth answers.
Always getting:
Could not find multi_json-1.3.0 in any of the sources
What it worked for me was deleting Gemfile.lock and running again bundle install
It installed a new version of multi_json:
Installing multi_json (1.3.2)
I ran into this problem too with a Rails 3.1 application + rails engines .
bundle exec rake -T reported the error you're reporting.
What solved it for me was running the following command to tell bundler to install the gems to the local 'vendor/bundle' path within the application with the following command:
bundle install --path=vendor/bundle
After I did that, bundle exec rake -T worked correctly.
I had the same problem, and used Jorge's answer to get to my solution:
bundle update multi_json
This just updates multi_json, and not all the other gems, which would potentially happen when you delete the Gemfile.lock and run "bundle install".
Always run your commands through bundle exec. That way you ensuer that you load the correct environment which is expected by your app. Use it like:
bundle exec rake db:migrate
Also make sure you have actually run bundle install to install all required gems and their dependencies.

Resources