I have a problem with a very simple Gemfile:
source :rubygems
gem 'mongo'
gem 'mongo_ext'
I installed the gems with "bundle install" but it doesn't load mongo_ext.
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'mongo'
**Notice: C extension not loaded. This is required for optimum MongoDB
Ruby driver performance. You can install the extension as follows:
gem install bson_ext
If you continue to receive this message after installing, make sure that the
bson_ext gem is in your load path and that the bson_ext and mongo gems are of
the same version.
=> true
But if I use the system irb I it is load:
$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mongo'
=> true
irb(main):003:0>
Maybe that behavior is because mongo_ext includes C extensions.
You need to add bson and bson_ext to your Gemfile:
source :rubygems
gem 'mongo'
gem 'mongo_ext'
gem 'bson'
gem 'bson_ext'
And generally speaking, it's a good idea to specify versions of the gems you are using. That way you can ensure your code works even if a gem makes breaking changes (or adds new bugs that affect you). Specify the newest version that is out at the time you start your project, but upgrade them only with care. Example:
source :rubygems
gem 'mongo', '1.5.1'
gem 'mongo_ext', '0.19.3'
gem 'bson', '1.5.1'
gem 'bson_ext', '1.5.1'
Related
I tried starting Zammad from cPanel, and when I executed the command
bundle install --without test development mysql
I got an error about the version of Ruby in the Gemfile:
Your ruby version is 2.4.3 but your Gemfile specified 2.5.5
I manually changed the version of Ruby in the Gemfile, but the error persists. It seems that it does not support my modification:
source 'https://rubygems.org'
# core - base
ruby '2.4.3'
gem 'rails', '5.2.3'
# core - rails additions
gem 'activerecord-import'
gem 'activerecord-session_store
gem 'bootsnap', require: false
gem 'composite_primary_keys'
gem 'json'
gem 'rails-observers'
In a ruby program, there is a separate Gem file, which contains the following definitions:
source "https://rubygems.org"
gem "typhoeus"
gem "json"
gem "pg"
gem "google_drive" , "2.1.11"
gem "mandrill-api"
If I do not want this gem file for some reason, then in ruby script, I need to add require for all the libraries,
such as:
require typhoeus
require json
require pg
require google_drive, 2.1.11
require mandrill-api
will this work?
The purpose of the Gemfile can be helpful so that you can insure your code will work by using bundler which allows you to run bundle install which will install the gems to work with the current version of ruby you will be using for your code. It will also add a Gemfile.lock file which is a good idea to commit in your version control to insure you have a working stack where the gems and the ruby version are all compatible.
If you only require the files in your script, there is no guaranteed that the gems are actually installed in the scope of that script's runner. So by having a Gemfile and Gemfile.lock and using bundler, you can have portability for your codebase.
Update
As per comment by #engineersmnky , you can specify gem version however with this syntax and it should work so long as those gems are installed. You would first need to make sure to install the version in your terminal:
gem install google_drive -v 2.1.11
Then you can do this in your ruby file
require 'rubygems'
gem 'google_drive', '2.1.11';
require 'google_drive'
require 'typhoeus'
require 'json'
require 'pg'
require 'mandrill-api'
I have the sqlite3 gem in my Gemfile. Running 'bundle install' works without errors. When running a dababase migration using Rake:
rake db:create_migration NAME=create_messages
I get the following error:
rake aborted!
LoadError: Could not load 'active_record/connection_adapters/sqlite_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
I even tried specifying sqlite3 with 1.3.3 and then with 1.3.4 versions in the Gemfile but that did not resolve the issue. Ruby version is 1.9.3
Following is from my environments.rb file:
configure :development do
set :database, 'sqlite:///dev.db'
set :show_exceptions, true
end
Following is from Gemfile:
source 'https://rubygems.org'
#ruby "1.9.3"
gem "sinatra"
gem "activerecord"
gem "sinatra-activerecord"
gem 'sinatra-flash'
gem 'sinatra-redirect-with-flash'
group :development do
gem 'sqlite3-ruby'
gem "tux"
end
I have also tried sqlite3 in place of sqlite3-ruby but that did not solve the issue.
Try this!
set :database, 'sqlite3:///dev.db'
This was resoved after upgrading to ruby v2.2.1 and updating all the gems again. I installed v2.2.1 via RVM.
My gemfile for my Ramaze (rack) app looks like this.
source 'http://rubygems.org'
ruby '1.9.3'
gem 'ramaze', "<= 2012.04.14" #old version
gem "innate", ">= 2012.03", "< 2012.11" #old version
gem 'rack', "<= 1.4.1"
gem 'sequel'
#if defined? ENV['RACK_ENV'] == 'production' then gem 'pg' else gem 'sqlite3' end
gem 'pg'
gem "sentry-raven", :git => "https://github.com/coderanger/raven-ruby.git"
gem 'bcrypt-ruby'
gem 'rdiscount'
gem 'redcarpet'
gem 'pony'
gem 'bacon'
gem 'koala'
gem 'stop_forum_spam'
#source 'http://mirror1.prod.rhcloud.com/mirror/ruby/'
#gem 'nokogiri'
#gem 'capybara'
As you can see, the pg gem is defined in it. However when I do a git push on Openshift, it installs every gem on my gem file EXCEPT for pg. I've done bundle install on my computer before a push with a force_clean_build file in the .openshift folder, and it didn't help.
I'm using the Sequel ORM and aren't even using a postgres database in my app, so changing the subject, I've no idea why it wants the pg gem in the first place.
Are you using Windows?
Try looking at this:
https://bugzilla.redhat.com/show_bug.cgi?id=1126343
I'm trying to use ruby-debug19 with Ruby 1.9.1p376 but am getting the following error:
test.rb:2:in `require': no such file to load -- ruby-debug19 (LoadError) from test.rb:2:in `<main>'
Here's test.rb:
require 'rubygems'
require 'ruby-debug19'
Here's the output of "gem list":
*** LOCAL GEMS ***
ruby-debug19 (0.11.6)
(etc.)
So running "ruby test.rb" generates the above error.
Am I doing this wrong? I thought this was the correct way to run ruby-debug19 (by including the gem and adding "debugger" statements) and haven't been able to find any articles/posts with the same problem.
I am using RVM but the above output is all under the same version of Ruby ("ruby -v" shows 1.9.1p376 as expected, and the gem list output is specific to that version and not the OS X system-installed version 1.8.7).
Try just
require 'ruby-debug'
(Despite the gem's name)
Also you don't need require 'rubygems' anymore when using Ruby 1.9.
For ruby 1.9.3 and Rails 3.2 with pow:
In your Gemfile:
group :development do
gem 'debugger'
end
And at the bottom of config/environments/development.rb:
require 'debugger'
Debugger.start_remote
Debugger.settings[:autoeval] = true
Then connect to the debugger in your terminal using:
rdebug -c
For bundler (rails 3):
gem 'ruby-debug19', :require => 'ruby-debug'