如何在 Windows 上为 Ruby 安装 sqlite3?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15480381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:38:50  来源:igfitidea点击:

How do I install sqlite3 for Ruby on Windows?

ruby-on-railsrubywindowssqlite

提问by chrisp

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.

作为 Ruby/Rails 的新手,在本周末尝试自己解决问题后,我试图在这里寻求建议。

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.

我在 FreeBSD 上完成了完整的 Ruby/Apache/Passenger 设置,我正在尝试完成使用 Windows 作为 Ruby 开发环境的任务。

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.htmltutorial 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.)

  • Ruby 已安装,v2.0.0p0 (2013-02-24) [x64-ming32]
  • 安装了 Rails,v.3.2.12
  • 我已经安装并注册了 Ruby 开发工具包。
  • 我已将 sqlite3 dll/exe 复制到 Ruby“bin”文件夹(使用“使用 Ruby 启动命令提示符”控制台也在我的路径中。)
  • 我可以成功启动 rails 服务器,并继续使用http://guides.rubyonrails.org/getting_started.html教程到 3.3。
  • ">rake db:create" 告诉我:

    请安装 sqlite3 适配器:(gem install activerecord-sqlite3-adaptersqlite3 不是捆绑包的一部分。将其添加到 Gemfile。)

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

我对此没有“了解”。尝试安装 activerecord-sqlite3-adapter 给我一个“找不到有效的 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.rbchecking for sqlite3.h... *** extconf.rb failed ***

  • ">gem install sqlite3" 返回:

    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.rbchecking 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.)

现在我陷入了困境,我什至不知道我的 Ruby on Windows 安装处于什么状态。我正在尝试遵循主要的 Rails 教程,但它没有指定任何这些问题(可能是因为 Ruby对于很多人来说,在 Windows 上似乎是一种自然的痛苦。)

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

我错过了什么?!?我只是想在 Windows 上为 Ruby 安装 sqlite3,看起来很简单吧?

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

如果我这样做">rais db",则会显示 SQLite shell:

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

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

类似问题的步骤不能解决我的问题: 在 Windows 7 上安装 SQLite 3.6

回答by Williams

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/82with 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:

即使问题已得到解答,我还是想发布我的研究以帮助他人。我在网上找到了很多信息,但作为一个 Ruby 新手,我很难理解。基本答案来自以下帖子https://github.com/luislavena/sqlite3-ruby/issues/82,其中包含“paulwis”关于如何为 ruby​​ 2.0.0-p0 正确安装 sqlite3 的说明以及对https 的一些评论: //github.com/rails/rails/issues/10150。所以这里是:

  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:\dev\sqlite3" 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=[path\to\sqlite3.h] --with-sqlite3-lib=[path\to\sqlite3.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)".
  1. 为您的设置安装 Ruby Devkit(DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe 因为我使用的是 x64 机器)
  2. 从 Sqlite.org 下载并解压 autoconf 包
  3. 运行 msys.bat(它在 ruby​​ devkit 根文件夹中)
  4. cd 进入您下载 sqlite 源代码的路径(例如:如果您不熟悉 MSYS/MINGW32,则路径“c:\dev\sqlite3”的“cd /c/dev/sqlite3”)
  5. 运行“./configure”
  6. 运行“制作”
  7. 运行“安装”
  8. 再次获取 sqlite3 gem,这次指定平台和新编译的二进制文件的路径:

    gem install sqlite3 --platform=ruby -- --with-sqlite3-include=[path\to\sqlite3.h] --with-sqlite3-lib=[path\to\sqlite3.o]
    

    例如:

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

    (来自步骤 4 中给出的路径)

  9. 检查 Rails 应用程序的 Gemfile.lock 并确保它指向正确的 sqlite3 版本。我的是“sqlite3(1.3.7-x86-mingw32)”并手动将其更改为“sqlite3(1.3.7-x64-mingw32)”。删除平台也有效:“sqlite3 (1.3.7)”。

Hope this helps someone.

希望这可以帮助某人。

回答by denis-bu

I was able to install sqlite3 with ruby2.0.0 on win XP32 with following command:

我能够使用以下命令在 win XP32 上安装带有 ruby​​2.0.0 的 sqlite3:

c:\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/distr/sqlite --with-sqlite3-include=C:/distr/sqlite

c:\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/distr/sqlite --with-sqlite3-include=C:/distr/sqlite

Folder C:/distr/sqlitecontains following files

文件夹C:/distr/sqlite包含以下文件

  • shell.c
  • sqlite3.c
  • sqlite3.h
  • sqlite3ext.h
  • sqlite3.def
  • sqlite3.dll
  • 外壳程序
  • sqlite3.c
  • sqlite3.h
  • sqlite3ext.h
  • sqlite3.def
  • sqlite3.dll

So, basically I've extract sqlite-amalgamation-3071602.zipand sqlite-dll-win32-x86-3071602.zipto C:/distr/sqlite.

所以,基本上我已经提取sqlite-amalgamation-3071602.zipsqlite-dll-win32-x86-3071602.zipC:/distr/sqlite.

HEADS UP

当心

You still need to put copy of sqlite3.dlland sqlite3.defsomewhere to PATH. IMHO it's best to keep sqlite3 binaries in ruby's bin folder.

您仍然需要将sqlite3.dllsqlite3.def某处的副本放在 PATH 中。恕我直言,最好将 sqlite3 二进制文件保存在 ruby​​ 的 bin 文件夹中。

回答by cmantas

This is an old thread, but still relevant.

这是一个旧线程,但仍然相关。

For us it was as simple as editing the Gemfileand adding a specific version for sqlite.

对我们来说,它就像编辑Gemfile和添加特定版本的 sqlite一样简单。

gem 'sqlite3', '~> 1.3.13'

回答by qkdreyer

#!/usr/bin/env sh

mkdir c:/sqlite3x86
wget -P c:/sqlite3x86 http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma
cd c:/sqlite3x86
bsdtar --lzma -xf c:/sqlite3x86/sqlite-3.7.15.2-x86-windows.tar.lzma
gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite3x86
cd c:/
rm -rf c:/sqlite3x86

回答by zawhtut

For windows, go to C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb

对于窗户,请转到 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb

and make sure

并确保

require "sqlite3"instead of native

require "sqlite3"而不是原生

回答by Lyndon S

回答by chrisp

I figured I'd put in an answer -- from the comments, for posterity's sake. The issue seemed to be that I grabbed a new version of Ruby/Rails (for Windows) that was not compatible "yet" with SQLite3.

我想我会给出一个答案——为了后代的缘故,从评论中。问题似乎是我获取了一个新版本的 Ruby/Rails(适用于 Windows),它“还”与 SQLite3 不兼容。

I downgraded to 1.9.x and was able to things running.

我降级到 1.9.x 并且能够运行。

回答by regularmike

The easiest way to get set up for Ruby on Rails on a Windows machine is by using the RailsInstaller, which automatically installs and configures sqlite3 for you. One step.

在 Windows 机器上设置 Ruby on Rails 的最简单方法是使用 RailsInstaller,它会自动为您安装和配置 sqlite3。一步。

http://railsinstaller.org/en

http://railsinstaller.org/en

回答by vamshi mannem

You should follow this procedure:

您应该遵循以下程序:

  1. gem install bundler(add in Gem file_)
  2. gem 'sqlite3', ' < 1.4'(add in Gem file_)
  1. gem install bundler(在 Gem 文件中添加_)
  2. gem 'sqlite3', ' < 1.4'(在 Gem 文件中添加_)

then run:

然后运行:

install bundler