Install sqlite3 on mac osx?
It's not installed via mac ports, so port doesn't know about it. You could either do an install via port or get rails to use the one that's installed on the Mac already.
How to get node-sqlite3 working on Mac M1?
After 4 days of digging, I have finally gotten it to work!!!
For anyone that might stumble on this:
The reason why sqlite3 won't behave is threefold:
When node sqlite3 is installed using
npm install sqlite3
, it fetches all dependencies and installs it. It then fetches the precompiled binary binding file for the target arch and platform. In my case we would wantnapi-v6-darwin-unknown-arm64
for ARM64 and darwin for Apple M1. There is no precompiled binary available yet for this Apple ARM64 and even if there is, the next paragraph will detail why it still won't work.The problem is that it determines the the system's platform and architecture using the binary compiling package
node-pre-gyp
and this very savior of a Github issue details hownode-pre-gyp
is not handling ARM architecture detection properly and basically mixing everything up. Because it's not detecting properly, even if we build our own binding with--build-from-source
when installing, it still won't work because it is compiling the wrong binding file for the wrong architecture. To make matters worse, if we don't use--build-from-source
, it just simply fetches the Intel precompiled binding file.napi-v6-darwin-unknown-x64
Now for some reason, during runtime, it now detects the architecture properly and tries to look for the ARM64 version of the binding file, it won't find it and will throw the feared error 'module not found' for
napi-v6-darwin-unknown-arm64
. It obviously won't find it and even if it does, it will throw wrong architecture error because we have the Intel version on boardnapi-v6-darwin-unknown-x64
.
So finally after digging at this for 4 days, here's how I got it working:
- Uninstall sqlite3:
npm uninstall sqlite3
- Install a fresh sqlite3, build it from source, specify the target arch and use fallback build with node-pre-gyp just to be safe:
npm install sqlite3 --build-from-source --target_arch=arm64 --fallback-to-build
- Now the correct binding file is compiled for the correct platform and architecture, on runtime it will find it and will run!
Ruby Sqlite3 installation sqlite3_libversion_number() macOS Sierra
I finally managed to solve this by specifying the built-in Mac OS X sqlite library directory on macOS Sierra 10.12.5 (16F73):
$ whereis sqlite3
/usr/bin/sqlite3
# if binary is in /usr/bin then library is typically in /usr/lib
$ gem install sqlite3 -- --with-sqlite3-lib=/usr/lib
Building native extensions with: '--with-sqlite3-lib=/usr/lib'
This could take a while...
Successfully installed sqlite3-1.3.13
Parsing documentation for sqlite3-1.3.13
Done installing documentation for sqlite3 after 0 seconds
1 gem installed
I tried specifying the Homebrew library directory but for some reason it didn't work:
$ brew ls --verbose sqlite3
/usr/local/Cellar/sqlite/3.19.3/.brew/sqlite.rb
/usr/local/Cellar/sqlite/3.19.3/bin/sqlite3
/usr/local/Cellar/sqlite/3.19.3/include/msvc.h
/usr/local/Cellar/sqlite/3.19.3/include/sqlite3.h
/usr/local/Cellar/sqlite/3.19.3/include/sqlite3ext.h
/usr/local/Cellar/sqlite/3.19.3/INSTALL_RECEIPT.json
/usr/local/Cellar/sqlite/3.19.3/lib/libsqlite3.0.dylib
/usr/local/Cellar/sqlite/3.19.3/lib/libsqlite3.a
/usr/local/Cellar/sqlite/3.19.3/lib/libsqlite3.dylib
/usr/local/Cellar/sqlite/3.19.3/lib/pkgconfig/sqlite3.pc
/usr/local/Cellar/sqlite/3.19.3/README.txt
/usr/local/Cellar/sqlite/3.19.3/share/man/man1/sqlite3.1
$ gem install sqlite3 -- --with-sqlite3-lib=/usr/local/Cellar/sqlite/3.19.3/lib
This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
...
If someone knows how to specify the Homebrew library directory, please let me know because that would provide a little more control over installation (supposedly MacPorts works but I no longer use it).
For anyone curious, here's the full command to install Ruby's Sequel:
gem install sequel mysql sqlite3 -- --with-sqlite3-lib=/usr/lib
And how to convert a Laravel Homestead MySQL database listening on host port 3306 to SQLite from my comment on the question:
sequel mysql://homestead:secret@192.168.10.10:3306/my_database -C sqlite://my_database.sqlite
Related Topics
Ruby Class Inheritance: What Is '<<' (Double Less Than)
Can You Get Db Username, Pw, Database Name in Rails
How to Get Ruby to Print a Full Backtrace Instead of a Truncated One
How to Round a Time Down to the Nearest 15 Minutes in Ruby
Convert a String to Regular Expression Ruby
Why Is Rake Db:Migrate:Reset Not Listed in Rake -T
Populating an Association with Children in Factory_Girl
Allow Public Connections to Local Ruby on Rails Development Server
What's the Difference Between These Ruby Namespace Conventions
Trouble Comparing Time with Rspec
Ruby Inject with Initial Being a Hash
How to Click First Link in List of Items After Upgrading to Capybara 2.0
Format the Date Using Ruby on Rails
What Is the Use of Secret_Key_Base in Rails 4
Getting Openssl::X509::Certificateerror Nested Asn1 Error on Ruby