0
votes

I'm trying to run rails server and there is problem with sqlite3.

When i run bin/rails server

Could not find gem 'sqlite3 (~> 1.4)' in locally installed gems.

Run bundle install to install missing gems.

So i try to run bundle install

Installing sqlite3 1.4.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

And the last thing I tried is checking the log file in /var/lib/gems/2.7.0/extensions/x86_64-linux/2.7.0/sqlite3-1.4.2/mkmf.log

package configuration for sqlite3 is not found find_header: checking for sqlite3.h... -------------------- no

"x86_64-linux-gnu-gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.7.0 -I/usr/include/ruby-2.7.0/ruby/backward -I/usr/include/ruby-2.7.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -ffile-prefix-map=/build/ruby2.7-aN7IdK/ruby2.7-2.7.3=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC conftest.c -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-z,relro -Wl,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -lruby-2.7 -lm -lc"

checked program was:

/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

"x86_64-linux-gnu-gcc -E -I/usr/include/x86_64-linux-gnu/ruby-2.7.0 -I/usr/include/ruby-2.7.0/ruby/backward -I/usr/include/ruby-2.7.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -ffile-prefix-map=/build/ruby2.7-aN7IdK/ruby2.7-2.7.3=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC conftest.c -o conftest.i" conftest.c:3:10: fatal error: sqlite3.h: No such file or directory

3 | #include <sqlite3.h>
  |          ^~~~~~~~~~~ compilation terminated.

checked program was:

/* begin */
1: #include "ruby.h"
2: 
3: #include <sqlite3.h>
/* end */

Any suggestion?

1
do you have sqlite3 installed locally if not then install it if yes then in your Gemfile replace gem 'sqlite3' line by gem ‘sqlite3’, git: “https://github.com/larskanis/sqlite3-ruby", branch: “add-gemspec” and then try bundle install again - Chandan
I tried your method sir, but it gives me another error. [!] There was an error parsing Gemfile: Undefined local variable or method `“add' for Gemfile. Bundler cannot continue. # from /home/chip/rbonrails/blog/Gemfile:9 # ------------------------------------------- # # Use sqlite3 as the database for Active Record > gem 'sqlite3', "git: “github.com/larskanis/sqlite3-ruby", branch: “add-gemspec” # # Use Puma as the app server > # ------------------------------------------- - Chip
change branch name to 1-3-stable and or remove then try - Chandan
An alternative is really just to skip sqlite completely and use Postgres, MySQL or whatver other database you're actually going to use for the project. The only point of sqlite is that its easy to setup if you want to fiddle around. If the setup is giving you trouble then its a waste of time. - max
I'll try that, thx for the advice - Chip

1 Answers

0
votes

You need to install sqlite3 header files first. For Fedora/CentOS/RHEL, the command is sudo dnf install sqlite3 sqlite3-devel. For Debian/Ubuntu, it must be sudo apt-get install sqlite3 libsqlite3-dev.

I am assuming that you're using a ruby version manager, and not the one from Linux package manager. If not so, then you probably have to use sudo bundle install, which would technically work, but it is not a good practise. You're better off with switching to PostgreSQL or MySQL.