Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

How do I install sqlite3 for Ruby on Windows?

Being really new to Ruby/Rails, and after attempting to resolve the issue myself this weekend I'm making an attempt to seek advice here.

I have a complete Ruby/Apache/Passenger setup done on FreeBSD, and I'm trying to accomplish the task of using Windows as a Ruby development environment.

So far:

  • Ruby is installed, v2.0.0p0 (2013-02-24) [x64-ming32]
  • Rails is installed, v.3.2.12
  • I have the Ruby dev kit installed and registered.
  • I have the sqlite3 dll/exe copied to the Ruby "bin" folder (which is also in my path using the "Start Command Prompt with Ruby" console.)
  • I can start a rails server successfully, and continuing with the http://guides.rubyonrails.org/getting_started.html tutorial to 3.3.
  • ">rake db:create" tells me:

    Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter ( sqlite3 is not part of the bundle. Add it to Gemfile.)

which I have no "understanding" of. Trying to install activerecord-sqlite3-adapter gives me a "Could not find a valid gem..."

  • ">gem install sqlite3" returns:

    Building native extensions. This could take a while... ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension.

    D:/Development/Ruby200-x64/bin/ruby.exe extconf.rb checking for sqlite3.h... *** extconf.rb failed ***

Right now I'm stuck at the point where I don't even know what state my Ruby on Windows installation is in. I'm trying to follow the main Rails tutorial and it doesn't specify any of these issues (probably because Ruby on Windows seems to be a natural pain for a lot of people.)

What am I missing?!? I'm just trying to install sqlite3 for Ruby on Windows, seems simple right?

If I do ">rais db" the SQLite shell is presented:

SQLite version 3.7.15.2 2013-01-09 11:53:05

Similar questions with steps that do not resolve my issue: Installing SQLite 3.6 On Windows 7

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Even though the question has been answered, I want to post my research to help others. I found a lot of information online, but being a Ruby newbie I had a tough time following all. The basic answer comes from the following post https://github.com/luislavena/sqlite3-ruby/issues/82 with instructions by "paulwis" on how to properly install sqlite3 for ruby 2.0.0-p0 and some comments on https://github.com/rails/rails/issues/10150 . So here it is:

  1. Install the Ruby Devkit for your setup (DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe for me since I use a x64 machine)
  2. Download and extract the autoconf package from Sqlite.org
  3. Run msys.bat (it is inside the ruby devkit root folder)
  4. cd into the path where you downloaded the sqlite source (for example: "cd /c/dev/sqlite3" for path "c:devsqlite3" if you are new to MSYS/MINGW32)
  5. Run "./configure"
  6. Run "make"
  7. Run "make install"
  8. Get the sqlite3 gem again, this time specifying the platform and the path to the newly compiled binaries:

    gem install sqlite3 --platform=ruby -- --with-sqlite3-include=[pathosqlite3.h] --with-sqlite3-lib=[pathosqlite3.o]
    

    For example:

    gem install sqlite3 --platform=ruby -- --with-sqlite3-include=/c:/dev/sqlite3/ --with-sqlite3-lib=/c:/dev/sqlite3/.libs/
    

    (from the paths given in step 4)

  9. Check the Gemfile.lock of your rails app and make sure that it points to the correct sqlite3 version. Mine was "sqlite3 (1.3.7-x86-mingw32)" and manually changed it to "sqlite3 (1.3.7-x64-mingw32)". Removing the platform also works: "sqlite3 (1.3.7)".

Hope this helps someone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...