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

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.

Related

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

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.

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.

Building gems with jRuby cext on Heroku

I am trying to use the JRuby Heroku buildpack (https://github.com/jruby/heroku-buildpack-jruby) to run a simple test application.
However, it seems that gems with C extensions cannot be compiled. For example, when doing a "git push heroku", the gems without C extensions are installed successfully, but then...
Using activerecord (3.1.3)
Using activeresource (3.1.3)
Using bouncy-castle-java (1.5.0146.1)
Using bson (1.7.0)
Installing bson_ext (1.7.0) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/tmp/build_10vcxrs9ayvxf/jruby/bin/jruby extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS or modify .jrubyrc to enable.
(root) at /tmp/build_10vcxrs9ayvxf/jruby/lib/ruby/shared/mkmf.rb:8
require at org/jruby/RubyKernel.java:1019
(root) at /tmp/build_10vcxrs9ayvxf/jruby/lib/ruby/shared/rubygems/custom_require.rb:1
(root) at extconf.rb:1
Gem files will remain installed in /tmp/build_10vcxrs9ayvxf/vendor/bundle/jruby/1.9/gems/bson_ext-1.7.0 for inspection.
Results logged to /tmp/build_10vcxrs9ayvxf/vendor/bundle/jruby/1.9/gems/bson_ext-1.7.0/ext/cbson/gem_make.out
An error occurred while installing bson_ext (1.7.0), and Bundler cannot continue.
Make sure that `gem install bson_ext -v '1.7.0'` succeeds before bundling.
Dependencies installed
Upon seeing the advice given above, I then went and created a modified version of the JRuby buildpack, which can be found here: https://github.com/grahamdaley/heroku-buildpack-jruby-cext
The only difference between this buildpack and the original one is that I have now set JRUBY_OPTS as follows:
JRUBY_OPTS="--1.9 -Xcext.enabled=true -J-Xmx400m"
However, this doesn't seem to have made any difference at all and I'm still getting the same error.
Any hints? Is it possible (and would help) to add a .jrubyrc file somewhere in the buildpack?
you should simply configure JRUBY_OPTS instead of a setting up a customized build-pack :
heroku config:add JRUBY_OPTS="--1.9 -Xcext.enabled=true -J-Xmx400m"
that being said - it's probably a bad idea to use C-ext with JRuby
you definitely do not need C-ext due to BSON gem (it has a native JRuby version) - editing your Gemfile and/or re-bundling (rm Gemfile.lock && bundle) locally with JRuby will likely solve this for you ...
Install without C extention
On way is just install json without the C extension. Is possible because the C extension is optional. Attention this is slower than bson with C extension this is may a problem for you. source
Ruby — with optional C extension
Open a Ticket
Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket.
So you can open a support ticket here

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.

Running padrinorb after installing says "Could not find padrino-core"

EDIT:
False alarm.
I was able to resolve the issue. Apparently I was to sudo happy and that broke the install of the gem.
I had to gem uninstall padrino, then gem install padrino.
Now it works flawlessly.
BTW, padrinorb is shaping up to be a nice balance between Sinatra and Rails.
// original post below:
Not sure what I did wrong.
I'm trying to test out Padrino, however I'm running into an issue straight away.
I'm following the steps starting with sudo gem install padrino adding sudo for good measure.
Then following along I did padrino g project myapp -d datamapper -b as their site states.
The problem is that it returns an error, so I decided to just run padrino as is with no args.
Error as well (it's long):
$ padrino
/Users/viper1092/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find padrino-core (>= 0) amongst [RedCloth-4.2.9, RedCloth-4.2.8, actionmailer-3.2.3, actionpack-3.2.3, activemodel-3.2.3, activerecord-3.2.3, activeresource-3.2.3, activesupport-3.2.3, addressable-2.2.7, albino-1.3.3, arel-3.0.2, blankslate-2.1.2.4, builder-3.0.0, bundler-1.1.3, bundler-1.0.22, chunky_png-1.2.5, chunky_png-1.2.1, classifier-1.3.3, coffee-rails-3.2.2, coffee-script-2.2.0, coffee-script-source-1.3.1, compass-0.12.1, compass-0.11.5, crack-0.1.8, daemons-1.1.3, directory_watcher-1.4.1, directory_watcher-1.4.0, erubis-2.7.0, eventmachine-0.12.10, execjs-1.3.0, faraday-0.7.6, fast-stemmer-1.0.1, fast-stemmer-1.0.0, ffi-1.0.11, ffi-1.0.9, fssm-0.2.9, fssm-0.2.7, haml-3.1.4, haml-3.1.2, heroku-2.24.1, heroku-2.20.1, hike-1.2.1, httparty-0.7.8, i18n-0.6.0, jekyll-0.11.2, jekyll-0.11.0, journey-1.0.3, jquery-rails-2.0.2, json-1.6.6, json-1.5.4, koala-1.3.0, kramdown-0.13.5, kramdown-0.13.3, launchy-2.1.0, launchy-2.0.5, liquid-2.3.0, liquid-2.2.2, mail-2.4.4, maruku-0.6.0, mime-types-1.18, mime-types-1.17.2, multi_json-1.2.0, multi_json-1.0.3, multipart-post-1.1.5, netrc-0.7.1, polyglot-0.3.3, posix-spawn-0.3.6, pygments.rb-0.2.11, pygments.rb-0.1.3, rack-1.4.1, rack-1.3.2, rack-cache-1.2, rack-protection-1.2.0, rack-ssl-1.3.2, rack-test-0.6.1, rails-3.2.3, railties-3.2.3, rake-0.9.2.2, rake-0.9.2, rb-fsevent-0.9.1, rb-fsevent-0.4.3.1, rdiscount-1.6.8, rdoc-3.12, rest-client-1.6.7, rubypants-0.2.0, rubypython-0.5.3, rubypython-0.5.1, rubyzip-0.9.7, rubyzip-0.9.6.1, sass-3.1.15, sass-3.1.5, sass-rails-3.2.5, sinatra-1.3.2, sinatra-1.2.6, sprockets-2.1.2, sqlite3-1.3.5, stringex-1.3.2, stringex-1.3.0, syntax-1.0.0, term-ansicolor-1.0.7, thin-1.2.11, thor-0.14.6, tilt-1.3.3, tilt-1.3.2, treetop-1.4.10, tzinfo-0.3.33, uglifier-1.2.4] (Gem::LoadError)
from /Users/viper1092/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /Users/viper1092/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
from /Users/viper1092/.rvm/rubies/ruby-1.9.2-p290/bin/padrino:18:in `<main>'
Then if I take a look at gem list:
$ gem list
*** LOCAL GEMS ***
polyglot (0.3.3)
posix-spawn (0.3.6)
pygments.rb (0.2.11, 0.1.3)
Those are the only "p"s I have.
When I ran sudo gem install padrino initially:
Successfully installed padrino-mailer-0.10.6
Successfully installed bundler-1.1.3
Successfully installed padrino-gen-0.10.6
Successfully installed padrino-cache-0.10.6
Successfully installed padrino-admin-0.10.6
Successfully installed padrino-0.10.6
21 gems installed
I'm on Mac OS X 10.7.3 running RVM 1.10.2 with ruby 1.9.2 selected.
I've tried just gemming Padrino 3 times as gem install padrino with no sudo just for fun and it reports that it installs, but padrino (with or without args) fails with same error. Again, running gem list does not mention padrino or padrino-core.
Any advice?
(I have the full verbosity and it's quite lengthy)
I was able to resolve the issue. Apparently I was to sudo happy and that broke the install of the gem.
I had to gem uninstall padrino, then gem install padrino.
Now it works flawlessly.
I suppose sudo installing changes some system-wide /usr deal, idk.
Thanks if you looked over my question.
BTW, padrinorb is shaping up to be a nice balance between Sinatra and Rails.

Resources