"rubygem mysql error: gem is not loaded" after CentOS upgrade - ruby

I am upgrading a system from EL 6 to EL 7. We have an application that uses ruby to setup a MySQL database. I know very, very little about ruby and gems, so I'm struggling getting this going. Under EL 6, the setup process works properly. Under CentOS 7, I get the following error when processing the rakefile:
Specified 'mysql' for database adapter, but the gem is not loaded. Add
gem 'mysql' to your Gemfile
Under 6, I don't see any MySQL gem files installed using gem list, but the setup process works fine and generates our database properly.
Under 7, I can manually run: gem install mysql --with-mysql-config=/usr/lib64/mysql/mysql_config.
Then, the setup script works.
I am installing most of the required gems/ruby applications via rpm.
I have:
ruby-2.0.0.648-29.el7.x86_64
rubygem-rake-0.9.6-29.el7.noarch
rubygem-activesupport-4.2.5.2-2.fc24.noarch
rubygems-2.0.14.1-29.el7.noarch
rubygem-activemodel-4.2.5.2-1.fc24.noarch
rubygem-activerecord-4.2.5.2-1.fc24.noarch
ruby-mysql-2.8.2-1.el7.x86_64
ruby-mysql creates /usr/local/lib64/ruby/site_ruby/mysql.so.
Is the mysql.so library what provides the MySQL adapter or is there something else that effectively provides the mysql gem? It's confusing that I don't have to do anything in EL 6 but have to install it specifically in EL 7.
Is this a pathing issue or a major change in source? I'm obviously pulling in the activesupport and activerecord rpms from Fedora, so I suppose there could be a conflict there, but it's very hard to tell.
My database.yml file looks like this:
adapter: mysql
encoding: utf8
database: mydatabase
username: root
password:
host: 127.0.0.1
port: 3306

Try use the mysql2 gem instead:
In your Gemfile:
gem 'mysql2'
and database.yml:
adapter: mysql2
Hope that would help.

So I'm not sure why there was never a gemfile in the original script. As mentioned in my OP, a basic solution was to run gem install mysql, but that was weird because previously it wasn't necessary.
What I think was happening:
Under EL6, the ruby-mysql rpm was putting the mysql.so in the proper location and basically issuing a gem install command. The EL7 version I have was not calling the proper setup macros in the rpm.
What I did to fix this:
i used gem2rpm (such a great rpm/package) to generate the rubygem-mysql spec file.
https://github.com/fedora-ruby/gem2rpm
gem2rpm --fetch mysql (to get the gem)
gem2rpm -T > rubygem-mysql.spec.template
gem2rpm -t rubygem-.spec.template mysql-2.9.1.gem > rubygem-mysql.spec
You have to modify the spec file a bit after it's generated, then use that to spec template to properly build the spec file for your needs.
Then just use rpmbuild to actually make the rpm/srpm.
gem list now shows mysql in there and the setup script works.

Related

Openshift and net-ssh incompatibility? (2.9.3-beta1 vs 2.9.2)

by searching to access my Postgres DB on Openshift, i'm currently facing problem using net-ssh.
At this step - note that the installed Ruby version is 2.2.0 and net-ssh is 2.9.3-beta1
To be able to access the DB from my local DB IDE, i need to execute:
rhc port-forward myappname
But the execution returns this error: Checking available ports ... Could not parse PKey: no start line
As you can see in this post (an other ones e.g. this one), the fix is to back to a stable version of net-ssh. the 2.9.2.
What i've succesfully done.
But now, running rhc port-forward myappname is giving me the following error: .../2.2.0/rubygems/core_ext/kernel_require.rb:54:in 'require': cannot load such file
And the fix is to upgrade net-ssh to the 2.9.3-Beta1 version (see this post).
This is really weird! Seems that "the snake is biting its own tail" (don't know if that french expression got english translation).
Note that i've tried to make a clean setup with new ssh key gen (automatically and manually).
My system is runnin' Win 7 64bits.
I made uninstall/install of last version of Ruby.
Reinstall of rhc.
Last version running on rhc-1.36.4. The problem goes on.
Can you help?
Should i install an older version of ssh-net and/or Ruby (i'm not allowed to use ssh-net 2.5.2 due to new version of rhc)?
(sorry for my bad english)
rhc/Gemfile & rhc/rhc.gemspec required gem "net-ssh", "<= 2.9.2"
net-ssh version 2.9.2 use require dl/import atleast on pageant.rb
dl/import is removed from ruby see https://github.com/ruby/ruby/blob/v2_2_0/NEWS#L148-L149
instead fiddle is recommended
net-ssh 3.* seems to fix this(uses fiddle/{import,{ for ruby >= 2.1)
net-ssh version 3. seems to have drop in compatibility(still working on mine) for rhc
So a simple hack is to modify rhc/Gemfile & rhc/rhc.gemspec and install the gem
A guy already have done it.
A Solution(Untested)
gem 'rhc', :git => 'git://github.com/thrasher-redhat/rhc.git'
from https://stackoverflow.com/a/7421712/2382629
Alternative Solution(Tested even on windows 7 32bit :p)
git clone https://github.com/openshift/rhc
cd rhc
modify rhc/Gemfile & rhc/rhc.gemspec like https://github.com/openshift/rhc/pull/748/files then
gem build rhc.gemspec
it should output like
blah! blah! blah! warnings and msgs......
Successfully built RubyGem
Name: rhc
Version: 1.38.4
File: rhc-1.38.4.gem
then run
gem install rhc-1.38.4.gem
You need to use an older version of Ruby, try 1.9.3 or 2.0, or maybe even 2.1.

Could not load 'active_record/connection_adapters/postgresql_adapter'

I have a Sinatra app using Postgres via Activerecord. I'm using RVM on a Mac and a number of gems including:
activerecord
activesupport
When I run the server (thin), I get an error:
Could not load 'active_record/connection_adapters/postgresql_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.
The adapter is set to postgresql in the config, and I've checked my RVM and paths: My Gem install path is set properly, and I can see the appropriate gems installed properly, and the specific adapter is there too, so really not sure what could be happening or how to further troubleshoot this?
Using Ruby 2.0.0-p598, activerecord and activesupport 4.1.4
--
Further debugging attempts:
ruby -v
ruby 2.0.0p598 (2014-11-13 revision 48408) [x86_64-darwin14.0.0]
which ruby
/Users/user/.rvm/rubies/ruby-2.0.0-p598/bin/ruby
gem env (relevant parts):
EXECUTABLE DIRECTORY: /Users/user/.rvm/gems/ruby-2.0.0-p598/bin
GEM PATHS:
/Users/user/.rvm/gems/ruby-2.0.0-p598
/Users/user/.rvm/gems/ruby-2.0.0-p598#global
SHELL PATH:
/Users/user/.rvm/gems/ruby-2.0.0-p598/bin
/Users/user/.rvm/gems/ruby-2.0.0-p598#global/bin
/Users/user/.rvm/rubies/ruby-2.0.0-p598/bin
ls $GEM_HOME/gems
activerecord-4.1.4
activesupport-4.1.4
Really at a loss for what else I can look into
database.yml
development:
adapter: postgresql
database: example_db
username: example_user
password: example_password
host: localhost
A next debugging step I took was to try using rvm to install a whole new version of ruby. This worked, so I used rvm to completely remove my old version of ruby with rvm remove 2.0.0-p598 and reinstall it again rvm install 2.0.0-p598.
I still have no idea what may have happened, but perhaps somehow something in the gem caches/builds were corrupted, so if anyone runs into a weird error like this where everything is in place but still doesn't work, try clearing everything with rvm and reinstalling.

Trouble with sqlite3 ruby 2.0 on Windows

I'm a newbie to programming, with ruby/rails successfully installed on my (mac) home computer. I'm trying to get ruby 2.0.0p195 (and Rails) set up on Windows at work (Windows 7, 32bit) and I'm failing on the sqlite3 installation. I've been through most of the solutions/suggestions I can find on the web, but just can't get it to work - the frustrating thing is that it tells me it's installed, but it doesn't work:
- I've tried the knapsack installation http://www.ruby-forum.com/topic/4413168
- If I try to install --with-opt-dir=c:/sqlite3 (or any of the many variations suggested) it gives a native extension error.
- I've put the .dll file in Ruby/bin, which is also in my PATH
- I have the devkit installed
The 'gem install sqlite3' command is successful, and if I do 'gem list', sqlite3 v1.3.7 x86-mingw32 appears in the list, but if I 'require sqlite3' in IRB I get:
LoadError: cannot load such file -- sqlite3/sqlite3_native
And the mkmf log says:
find_header: checking for sqlite3.h... -------------------- no
But I've confirmed the sqlite3.h file (and the sqlite3.c, sqlite3.o, and sqlite3.h files) is in my c:\sqlite3 directory, and as noted above, I've also tried installing '--with-opt-dir'.
So next I trace the error when I 'require' sqlite to a file '\kernel_require.rb' in ruby/lib, and it references to this:
if Gem::Specification.unresolved_deps.empty? then
return gem_original_require(path)
end
I'm lost, and WAY out of my depth. At this point my only solution would be either to completely uninstall and start again, or to downgrade to ruby 1.9.x, but others seem to have sqlite3 and ruby 2.0 working so it's obviously (?) semi-stable. Help?
UPDATE: I've now tried downgrading to ruby 1.9.3, and apart from pik reverting to the most recent version of ruby every time I shut the command line, I can actually get the server to run etc. So it seems this issue is related specifically to ruby 2.0.
I am encountering the same issue, except that I don't really think that it is related to Ruby 2, but to rails 4 instead.
I have managed to install the sqlite3 gem by downloading the source, dll and exec (dll and executables need to be added to PATH accessible) and installying the gem with the follwing process:
Download:
http://www.sqlite.org/2013/sqlite-amalgamation-3071700.zip
http://www.sqlite.org/2013/sqlite-dll-win32-x86-3071700.zip
Extract and put the files in a location on your C drive or wherever you want. Then copy sqlite.dll and sqlite.def to the Ruby/bin directory.
Then you go to the DevKit directory and run msys.bat, in which you issue the following command:
gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=path-to-sqlite --with-sqlite3-include=path-to-sqlite
This allowed me to install the gem successfully (using Ruby-2.0.0-p247 x86 and devkit). I validated through irb doing:
require 'sqlite3'
SQLite3::SQLITE_VERSION
I'm still trying to figure out this issue.
I get the same error message when I try to start the server or whenever I try to run the rails console.
I'd love to get this issue fixed...

Why I can't install postgresql with rails 4.0.0.rc1 (ruby 2.0)

first time on forum so i will try to be as specific as one can be, sorry for any possible typos ok?
I am relatively new to rails (less than a year), and i want to make a default project to work with it. I have always used sqlite3 in development and pg in production (heroku), but now i want to make things right (i've encountered problems with sqlite3 running ok but pg not) and use both pg in production and devlop.
I have spent 2 days searching foruns and all the anwsers are old or other versions/other OS.
I'll try to list the steps i took for setting up my stage:
Here my configs:
-OS: Windows 7 64x
-Editor: Aptana Studio
-PostGresql
-Rails 4.0.0.rc1
-Ruby 2.0
Download and Install postgresql-9.2.4-1-windows-x64
Set a default Password to postgresql
Create an Role "my_user" in postgresql with all privilegies
Create an testing database "rails_test"
Open Aptana Studio and init an new default project going to the project folder and than running "rails new . -d postgresql" for generate the new project.
Install the pg gem "gem install pg" "gem list" shows the pg gem correctly
configure "database.yml" for using the correct username and password
development:
adapter: postgresql
encoding: unicode
database: rails_test
pool: 5
username: my_user
password: 12345
Running some commands in ruby like "gem update", "bundle install"
then when i try to generate an model and use rake db:migrate i get the following error:
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.
and it's true if i run "bundle show pg" i get the message:
Could not find gem 'pg'. Did you mean pg?
If i open my gemfile the pg gem is there, but the bundler is not getting it !
Any ideias to help this little amateur?
TNX !
(Windows 7 x64, Ruby2.0.0p247-x64, Rails4.0.0, Postgresql 9.2.4 x64, pg 0.15.1, mysql2 0.3.11)
There seems to be a platform detection/verification problem with bundler. While what I did is a hack of the Gemfile.lock file (I know, I know...), I have a (hopefully) temporary solution:
Edit Gemfile.lock, and
Find the line for 'pg':
multi_json (1.7.7)
pg (0.15.1-x86-mingw32)
polyglot (0.3.3)
Copy the line, and modify the new copy to :
multi_json (1.7.7)
pg (0.15.1-x64-mingw32)
pg (0.15.1-x86-mingw32)
polyglot (0.3.3)
This is how the x64 version of the installed gem announces itself when you ask to list it (gem list pg).
For anyone who cares, the exact same problem was (sometimes) encountered with the mysql2 gem.
I had this problem and solved it by using the 32bit version of ruby rather than the 64bit. You need to make sure the devkit matches up to your version as well. So if you have the 64 bit version of that installed then that will need to be changed too.

installing sqlite3 for ruby

I've installed the latest version of ruby and mysql but still when i try and run something through aptana with 'requires 'rubygems' and 'requires 'sqlite3' i get the following appear in the console:
/home/carladessi/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in`require': cannot load such file -- sqlite3 (LoadError)
from /home/carladessi/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'from /home/carladessi/Documents/Aptana Studio 3 Workspace/Test/rubydb.rb:2:in `<main>'
The error you posted is for sqlite3 and not MySQL. I've not used Apatana Studio bit it looks as if it, or your program is requesting sqlite3, not MySQL. Check your Gemfile, if you have one, for sqlite3. Also check Apatana Studio requirements to see if it requires sqlite3.
Updated to reflect change in question:
It looks as though you're using RVM. Try the following from the terminal.
1.If you are using a Gemfile and bundler then on the terminal ensure you're executing your application with bundle exec. For instance:
bundle exec myapp.rb
Make sure that you are using the same gemset to which you installed sqlite3 with gem install sqlite.

Resources