Skip to main content

Error al crear un nuevo proyecto en Ruby on Rails - Gema SQLite 3



Ruby on Rails




Gema Sqlite 3

Hola a todos!
Estoy escribiendo sobre los errores que encontre mientra intentaba instalar Ruby on Rails nuevamente desde cero en un sistema Windows, el principal error que encontre fue con la gema SQLite3 cuando intentaba crear un nuevo proyecto.
Instale muchas veces Ruby On Rails en el pasado usando Ruby Installer de https://rubyinstaller.org/ y Rails Installer (Ruby 2.3 and Ruby 2.2) de http://railsinstaller.org
Pero esta vez no fue tan simple como siempre.
Con SQLite 3 ya instalado con version 3.26.0

C:\Sites>sqlite3 -version
3.26.0 2018-12-01 12:34:55 bf8c1b2b7a5960c282e543b9c293686dccff272512d08865f4600
fb58238b4f9

Instalé Rails con railsinstaller-3.4.0.exe y luego instale el Ruby Devkit rubyinstaller-devkit-2.6.1-1-x64.exe. 
C:\Sites>ruby -v
ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32]

C:\Sites>rails -v
Rails 5.2.2

Abri la consola y corrí el famoso Hello World

C:\Sites>rails new blog
 
 

Comenzó bien pero aparecio un error unos minutos despues
Fetching sqlite3 1.4.0
Installing sqlite3 1.4.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/sqlite3-1.4.0/ext/sqlite3
C:/RailsInstaller/Ruby2.3.3/bin/ruby.exe -I
C:/RailsInstaller/Ruby2.3.3/lib/ruby/site_ruby/2.3.0 -r
./siteconf20190217-4316-6m19zc.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/RailsInstaller/Ruby2.3.3/bin/$(RUBY_BASE_NAME)
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlcipher
        --without-sqlcipher
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can

be found here:

C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sql
ite3-1.4.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/sqlite3-1.4.0 for
inspection.
Results logged to
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sql
ite3-1.4.0/gem_make.out

An error occurred while installing sqlite3 (1.4.0), and Bundler cannot continue.

Make sure that `gem install sqlite3 -v '1.4.0' --source 'https://rubygems.org/'`

succeeds before bundling.

In Gemfile:
  sqlite3

C:\Sites>

Asi que sobre esto, aqui estan algunas de las soluciones que intente y NO funcionaron pero dependiendo de la configuracion de su entorno puede que sean utiles para algunos de ustedes

1* Descargar y compilar los archivos de https://www.sqlite.org/download.html 
La pagina oficial tiene una guia muy bien explicada de como y cuales archivos descargar y compilar aqui https://www.sqlite.org/howtocompile.html
Ademas para aquellos que estan comenzando...

If using the MinGW compiler, the command-line is this:
gcc -shared sqlite3.c -o sqlite3.dll
El compilador MinGW se encuentra en C:\Ruby26-x64\msys64 o C:\Ruby26-x32\msys32 (dependiendo de tu sistema y tu instalacion de Ruby) es un archivo .exe que abre una consola de linea de comandos.
Es recomendado poner la carpeta SQLite a compilar en el directorio raiz (C:/) porque devuelve un error si una de las carpetas tiene un nombre con caracteres especiales o espacios
-bash: cd: too many arguments
Usualmente esto es suficiente pero si esto no funciona puedes descargar el MinGW Installer Manager para obtener los archivos faltantes
http://www.mingw.org/wiki/Getting_Started













2* Agregar la carpeta compilada de SQLite 3 al PATH (no solo el archivo compilado sqlite3.dll, tambien los archivos de la carpeta sqlite-tools-win32-x86-3260000 )
3* Corriendo el comando para crear un nuevo proyecto y luego de que falle, modificar el archivo Gemfile
gem 'sqlite3',  '1.3.11'
Cambiar esta linea por alguna de estas 3 abajo:
gem 'sqlite3', git: "https://github.com/sparklemotion/sqlite3-ruby"
gem 'sqlite3', git: "https://github.com/sparklemotion/sqlite3-ruby", branch: "add-gemspec"
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
Tambien se puede remover esta linea
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
end
Y correr nuevamente el comando "bundle install"
C:\Sites>cd project_name
C:\Sites\project_name>bundle install

Acerca de esta solucion debo decir que depende de la configuracion de la instalacion para cual opcion resulte ya que en mi caso cuando instalaba primero RubyInstaller y luego RailsInstaller funciona pero si es al reves el sistema no encuentra los archivos MinGW y devuelve error, incluso modificando el PATH para usar los archivos del Ruby Devkit, donde esta MinGW, el sistema sigue buscando dentro de C:/RailsInstaller/Ruby2.3.3/
Es realmente una pena porque cuando intentas instalar una gema globalmente para todos los proyectos te devuelve "Gemfile not found"
Asi que solo funcionara repitiendo estos pasos por cada proyecto que se cree y si el sistema esta correctamente configurado
4* Intente descargando la gema desde https://rubygems.org/ e instalarla usando el parametro --local = 'path'
gem install --local C:\gemdownloadfolder\sqlite3-1.4.0.gem
Esto no funciono por los errores de la configuracion que quedaron por installar primero RailsInstaller y luego RubyInstaller pero otros desarrolladores han tenido 0 inconvenientes con esta solucion

Final solution

5* Desinstalar Rails utilizando el ejecutable en C:/RailsInstaller/ luego de que termine remover las carpetas remanentes o sino el sistema seguira buscando "ruby" en "C:/RailsInstaller/Ruby2.3.3/bin" incluso cuando esta vacia y retornara un folder is missing (no dejar ningun archivo sirve para forzar el sistema a reconocer ruby en la carpeta "C:\Ruby26-x64\bin" como unico disponible).
Ok, ahora solo nos queda Ruby DevKit y SQLite 3 instalados.
Executar el siguiente comando para instalar rails atravez de la linea de comandos
C:\Sites>gem install rails
cuando finalize instalar MinGW
C:\Sites>ridk exec pacman -S mingw-w64-x86_64-dlfcn
si MinGW no esta instalado en una carpeta reconocible por el sistema devolvera este error
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.0/ext/
sqlite3
C:/Ruby26-x64/bin/ruby.exe -I C:/Ruby26-x64/lib/ruby/2.6.0 -r ./siteconf20190221
-4120-l5mva9.rb extconf.rb
checking for sqlite3.h... yes
checking for pthread_create() in -lpthread... yes
checking for -ldl... no
checking for dlopen()... no
missing function dlopen
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.
Descargar la gema de SQLite3 de https://rubygems.org/ y guardarla en local. Entonces correr la linea de comandos desde esa carpeta. Puedes correrlo por cada proyecto o globalmente.
C:\Sites>gem install --local C:\sqlite3-1.4.0.gem
Temporarily enhancing PATH for MSYS/MINGW...
Installing required msys2 packages: mingw-w64-x86_64-sqlite3
warning: mingw-w64-x86_64-sqlite3-3.27.0-1 is up to date -- skipping
Building native extensions. This could take a while...
Successfully installed sqlite3-1.4.0
Parsing documentation for sqlite3-1.4.0
Installing ri documentation for sqlite3-1.4.0
Done installing documentation for sqlite3 after 2 seconds
1 gem installed

C:\Sites>
Si se corre en la carpeta Sites en vez de en un proyecto especifico no se volvera a producir el error cuando crees un nuevo proyecto
C:\Sites>rails new demo5
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from "."
Initialized empty Git repository in C:/sites2/demo5/.git/
      create  package.json
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/javascripts/application.js
      create  app/assets/javascripts/cable.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images/.keep
      create  app/assets/javascripts/channels
      create  app/assets/javascripts/channels/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/update
      create  bin/yarn
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_5_2.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp
      create  tmp/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  storage
      create  storage/.keep
      create  tmp/storage
      create  tmp/storage/.keep
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_5_2.rb
         run  bundle install
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...........
Using rake 12.3.2
Using concurrent-ruby 1.1.4
Using i18n 1.5.3
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.2
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.1 (x64-mingw32)
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.0.4
Using actionview 5.2.2
Using rack 2.0.6
Using rack-test 1.1.0
Using actionpack 5.2.2
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using websocket-driver 0.7.0
Using actioncable 5.2.2
Using globalid 0.4.2
Using activejob 5.2.2
Using mini_mime 1.0.1
Using mail 2.7.1
Using actionmailer 5.2.2
Using activemodel 5.2.2
Using arel 9.0.0
Using activerecord 5.2.2
Using mimemagic 0.3.3
Using marcel 0.3.3
Using activestorage 5.2.2
Using public_suffix 3.0.3
Using addressable 2.6.0
Using io-like 0.3.0
Using archive-zip 0.11.0
Using bindex 0.5.0
Using msgpack 1.2.6 (x64-mingw32)
Using bootsnap 1.4.0
Using bundler 1.17.2
Using byebug 11.0.0
Using regexp_parser 1.3.0
Using xpath 3.2.0
Using capybara 3.13.2
Using ffi 1.10.0 (x64-mingw32)
Using childprocess 0.9.0
Using chromedriver-helper 2.1.0
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.2
Using thor 0.20.3
Using railties 5.2.2
Using coffee-rails 4.2.2
Using duktape 2.0.1.0
Using multi_json 1.13.1
Using jbuilder 2.8.0
Using puma 3.12.0
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.2.2
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.0
Using rubyzip 1.2.2
Using sass-listen 4.0.0
Using sass 3.7.3
Using tilt 2.0.9
Using sass-rails 5.0.7
Using selenium-webdriver 3.141.0
Using sqlite3 1.4.0
Fetching turbolinks-source 5.2.0
Installing turbolinks-source 5.2.0
Fetching turbolinks 5.2.0
Installing turbolinks 5.2.0
Fetching tzinfo-data 1.2018.9
Installing tzinfo-data 1.2018.9
Fetching uglifier 4.1.20
Installing uglifier 4.1.20
Fetching web-console 3.7.0
Installing web-console 3.7.0
Bundle complete! 16 Gemfile dependencies, 77 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

...
Using selenium-webdriver 3.141.0
Using sqlite3 1.4.0
Fetching turbolinks-source 5.2.0
...
Buena suerte!
Hay mucha gente que prefiere utilizar Ruby on Rails con PostgreSQL pero hay muchos otros que necesitan o prefieren SQLite 3 por que es una base de datos basada en archivos, lo que la hace mas rapida que otras y portable.
Por ejemplo es perfecta para aplicaciones de un solo usuario, un juego, aplicaciones cross-platform que actuan como nativas o porque es mas facil el testeo durante la etapa de desarrollo.
Tambien se ha vuelto muy util ya que Javascript, Node.JS, Phonegap, Xamarin y Android Java pueden conectar con bases de datos SQLite que son guardadas localmente en los dispositivos.
Actualmente hay muchas paginas que aprovechan esta utilidad para evitar la perdida de informacion por cortes de internet, operaciones que fallan, entre otras.
O simplemente para evitar transferir informacion innecesaria a la nube, ya sea por seguridad del usuario, performance, rapidez de respuesta, asi como evitar el uso innecesario de espacio de disco en el servidor o banda ancha.
Esto ha abierto una increible cantidad de nuevas posibilidades y funcionalidades, especialmente desde que Ruby on Rails, conocido por ser una tecnologia de back-end fuerte y segura comenzara a ser utilizada para construir APIs con Ruby on Rails API, de esta forma muchos sitios web han sido complementados con aplicaciones moviles nativas

Comments