Rake db:create fails on Library not loaded - ruby-on-rails

I was running PostgreSQL 9.1, installed from Postgres (/Library/PostgreSQL/9.1) - ie not homebrew etc and on Mac OSX Leopard.
I upgraded to Snow Leopard and then immediately to Mountain Lion and had a mass of problems with gems failing to build etc, but got them fixed
Rails server crashed on startup with pg issues & I tried everything I could find but could not fix the prob - fixes included links etc, which may still persist (hence this background info might inform the solution)
I uninstalled postgresql 9.1 and installed Postgres App
Now on rake db:create I get the following:
rake aborted!
dlopen(/Users/mitch/.rvm/gems/ruby-1.9.2-p320#tme-3.2.11-mltest/gems/pg-0.17.0/lib/pg_ext.bundle, 9): Library not loaded: #loader_path/../lib/libpq.5.dylib
Referenced from: /Users/mitch/.rvm/gems/ruby-1.9.2-p320#tme-3.2.11-mltest/gems/pg-0.17.0/lib/pg_ext.bundle
Reason: no suitable image found. Did find:
/usr/local/lib/libpq.5.dylib: mach-o, but wrong architecture - /Users/mitch/.rvm/gems/ruby-1.9.2-p320#tme-3.2.11-mltest/gems/pg-0.17.0/lib/pg_ext.bundle
I'm running rvm (as u can see) and after the OS upgrade created a new gemset and installed Ruby
I've changed my path to reflect the advice of Postgresql App, after the OS upgrade I installed Xcode 5 and the command line tools as advised and I think my database.yaml file is ok
I suspect the problem might be connected with sym-links made earlier in the process, but I'm stuck to find the solution

Sounds like something has gone wrong in your Ruby installation. Try reinstalling Ruby Enterprise Edition via RVM:
rvm reinstall ree

I was experiencing the same issue with a different version of libpq. What I ended up doing is creating a link to the correct file:
sudo ln -s /Applications/Postgres93.app/Contents/MacOS/lib/libpq.5.6.dylib /usr/local/lib/
My previous answer was deleted as it wasn't originally an answer, just a confirmation of a similar issue. Hope this helps!

In the end I think this was tied up with the fact that Mountain Lion ships with Postgresql rather than MySQL as per previous OSX versions.
I couldn't make sense of the Postgres App, so I uninstalled it and also uninstalled the version of Postgresql that shipped with ML and then did a Homebrew install of the latest version of Postgresql (which places it in a different place than if you install it direct from the Postgresql site).
This seemed to straighten everything up

Related

Is there a simple way to install rails on OS X 10.11 El Capitan

The instructions for older OS don't seem to work well with system integrity protection enabled on OS X El capitan 10.11.1
What options for a http://railsinstaller.org or another one package, streamlined install to get rails running?
first of all you need ruby... as you are on OS x EL capitan you already have ruby... so first step done... ruby is the programming language... rails is the framework ... so you already have the language now you want the framework...
next is you need to install bundler (package manager for ruby):
gem install bundler
then you can install rails:
gem install rails
so now you can create a new project with:
rails new my_app_name
when you did this you will recognize that after the creation of a bunch of things it executes bundle install... so afterwards you should be able to start your app with:
rails s
If an error occurs during the installation just lookup the error by a quick google search... most of the time it is just a dependency that you are missing... also depending on which tutorial you tried you may need to start mysql first... or execute something like: rake db:create (create a database in your chosen database) and afterwards: rake db:migrate to create some tables (but this depends on the previous tutorial) try to get the welcome page from rails first ... you should get it in your browser with the adress: localhost:3000
Apple installs /usr/bin/rails to walk you through the official installation instructions as part of the core OS install if you ever run the program. Many of the old instructions will break since they don't play well with System Integrity Protection that's new on 10.11.
First make sure your command line tools are installed:
xcode-select install
Then follow the instructions (if any) you get from checking on the installed version of rails:
rails --version
this is a great site : https://gorails.com/setup/osx/10.11-el-capitan
However if you experience
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
on terminal after using gem install you must install command line tool via Xcode -> Preferences -> Downloads or https://developer.apple.com/downloads/
if you have newer Xcode versions
If you're not using homebrew and rvm, I implore you to do so! Now that you're on a fresh install, this may be the right time to get these habits down... I know it has a learning curve, but both will make your life incredibly easier later down the road, specially rvm! :)
This article describes how a user got it done... they basically compiled a ruby on el capitan.
http://www.railsbling.com/posts/el-capitan-homebrew-ruby-qt5-java/
rvm is way better than what any railsinstaller or shellscript would...

Problems finding ruby, rails, git after bungled PostgreSQL install

I had rails working fine for several weeks but I tried to install PostgreSQL to match Heroku and it failed to work. Now, when I open the terminal it pretend rails is not there and sets the default ruby to 1.8.7. When I start RVM it finds the right version of ruby and finds rails again and can start the server but each time I open a new shell it's back to not finding anything. Plus, the git commands don't work even after starting rvm.
I have set rvm to start by default but that doesn't work either, it has to be started manually, and it still doesn't fix the git issue.
More Detail
I am installing on Mountain Lion. This already has Postgres but the tutorial I was using suggested installing fresh using Homebrew. The trouble was the Homebrew installation installs to /usr/local/var/postgres and the installed ppstgres installs to usr/var/postgres. The system automatically uses the usr/var/postgres version, so following the tutorial I chnaged the order of usr/local/bin and usr/bin in etc/paths. That didn't help so I changed it back. Everything then went to hell so I reinstalled Mountain Lion but nothing had changed.
There are two known problems with loading RVM & default ruby:
login shell: go to terminal emulator preferences and enable login shell, sometimes it might be required to use /bin/bash --login instead.
ZSH (+ Oh-My-ZSH): go to ~/.zshrc and comment out any lines starting with: PATH= or path=(, it is still possible to use those but they need to reference itself like: PATH=$PATH:HOME/.rvm/bin or path+=( $HOME/.rvm/bin ) - which update and not reset PATH. This might be a bug in terminal emulator or ZSH ...
The git issue is explained by the reinstall of Mountain Lion which did not automatically install the command line tools. That now works. The only pain is having to load rvm every time now.

Rails Server broken after PostgreSQL download

Operating System I am using is Mac OSX Mountain Lion.
First I will give some back story on how this cluster F started. I am going through a Ruby on Rails Web development book. I want to use PostgreSQL as my server. Before today I was using sqlite3. I downloaded PostgreSQL 9.1 from there website. I used the DMG installer. Once I was done with the install process it asked me to re-boot because of some sort of memory problem, I did that and it installed without error.
The problem started when I tried to use the "Rails Server" command in the terminal. This is what I got (I tried to strip out the unimportant stuff which would clutter everything up)
/Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/pg-0.12.2/lib/pg.rb:4:in `require': dlopen(/Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/pg-0.12.2/lib/pg_ext.bundle, 9): Library not loaded: /usr/lib/libcrypto.dylib (LoadError)
Referenced from: /usr/lib/libpq.5.dylib
Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libcrypto.0.9.8.dylib provides version 0.9.8 - /Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/pg-0.12.2/lib/pg_ext.bundle
...
from /Users/Chris/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/gems/railties-3.2.8/lib/rails/commands.rb:50:in
I have read through the out put and I have done a lot of Google searching, and what I have found is that it's a problem with which version of libcrypto the server is fetching. Or something about the libssl. I have gone through the solutions on google and nothing seems to be working. Hopefully someone has had the same problem I have, and can help me.
Thanks in advance! -Chris
I really recommend you to use Homebrew to install postrgresql. It helps you to install all proper dependencies for version which correctly works with rails.
$ brew install postgresql
Do not forget to follow after install instructions from homebrew
Are you sure you installed PostgreSQL server/rubygem successfully? From the stack trace I think there's a problem about it.
If your PostgreSQL server/rubygem are working well, then switch another webserver, mongrel/thin are both OK, both have better performance than the default rails server(webrick) and easy to use.

RSpec stopped working after upgrading to OSX Lion

dyld: Library not loaded: /System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libclparser.dylib
Referenced from: /opt/local/bin/identify
Reason: image not found
Does anyone have a solution? Would upgrading Xcode to 4.1 help?
I'd recommend installing the latest XCode, 4.1, from the App Store before you do anything else, so as to get the latest build tools and dev libraries.
You'll likely need to recompile any Gems with native bindings (which it looks like you have, since something is looking for OpenCL, likely not RSPec itself).
To recompile all your gems run:
gem pristine --all
dydl errors are commonly associated with database drivers/bindings. Try re-installing your database if neither of the above work.
Your /opt/local/bin/identify is probably ImageMagick’s identify.
You probably need to rebuild your installation of ImageMagick. Based on the pathname (/opt/local/), you probably installed it as a part of MacPorts.
You should probably follow the instructions for Migrating a MacPorts install to a new major OS version or CPU architecture: install new Xcode, install latest MacPorts base, record installed ports, remove ports, reinstall ports.
Unfortunately, MacPorts’ bug #30322 indicates that the ImageMagick port may not yet build properly under Lion (found via MacPorts’ Lion Problems page).
I had a problem similar to this after a clean install of Lion, with Xcode 4.1 installed (both from the Mac App Store).
What eventually fixed it was running sudo gem install rspec -v 2.6.0. The actual problem (for me, your mileage may vary) was that the script stub wasn't being installed in /usr/bin, which meant the OS couldn't find RSpec without a full path spec.

Installing PostgreSQL on OSX for Rails development

I've spent several hours over the past few days trying to get PostgreSQL to play nice with RoR on my Mac.
I've followed several tutorials using several different methods such as installing PostgreSQL manually and installing from various 1-click installers
However the all the different methods I tried failed on the last step of installing the pg gem. Very frustrating!
Does anyone here have a tried and tested tutorial for getting this done? (Or would you like to write some instructions here...?)
My environment is this: Macbook running OSX 10.6, PostgreSQL 8.4.1 server
I think I've managed to find a way that works. I'm borrowing heavily from this great post1, but since they are installing a bunch of other stuff at the same time I'm going to write out what I did here for people who are just looking for the PostgreSQL install answer.
1 Editor's note: Link seemed dead when I tried. Is this the one? http://blog.blackwhale.at/?p=175#PostgreSQL Please fix if it is.
Download PostgreSQL for Mac and download the ‘Postgres.app’ installer.
Create a user for your rails development (keep in mind that if you're sharing an application during development you'll probably want the same user between all members your dev team in order to avoid headaches)
sudo -u postgres /Library/PostgreSQL8/bin/createuser
Enter your Mac OS X system user name as role name, and make it a superuser.
Install the pg gem so Rails can talk to PostgreSQL
sudo env PATH=/Library/PostgreSQL8/bin:$PATH gem install pg
Configure your rails app to talk to PostgreSQL. You can either create a new application with:
rails *appname* -d postgresql (for Rails 3 -> rails new *appname* -d postgresql)
Or for an existing app, modify your database.yml file.
This worked for me without any hiccups. If anyone else tries using this method I'd be interested to hear some feedback on how it went for you.
On a 64-bit Mac (Snow Leopard with Core 2 Duo or newer) I had to compile PostgreSQL from source, as rails kept complaining that:
*** Your PostgreSQL installation doesn't seem to have an architecture in common
with the running ruby interpreter (["ppc", "i386", "x86_64"] vs. [])
The architecture mismatch was probably bc I'd compiled rails from source, which defaulted to 64-bit. The binary installer on postgresql.org seemed only a 32-bit version. Setting ARCHFLAGS didn't fix this for me.
Anyhow, if you download the [source][1] from postgresql.org and follow the instructions in the INSTALL file, it's fairly straightforward. You don't have to create a new user if you use your own account. I did have to create the sysctl.conf file to expand shared memory - just google 'postgresql os x sysctl.conf'
Old question, but still maybe i can help someone with this (rather simple) solution:
gem install pg -- --with-opt-include=/opt/local/include/postgresql84/ --with-opt-lib=/opt/local/lib/postgresql84/
Download and Install MacPorts
fire up terminal
sudo port install ruby postgresql83-server rb-postgres rb-gems rb-rails
Thanks to Ganesh for the good awnser, my sudo url looked a bit diffirent :) here is what I havesudo -u postgres /Library/PostgreSQL/9.2/bin/createuser
Ryan Bate's Railscast on PostgreSQL walks you through setting it up on a Mac with Homebrew. Very easy, worked for me on OSX 10.6.8.

Resources