Mac, Rails 4: install `tiny_tds` gem with `freetds` - macos

We're using activerecord-sqlserver-adapter adapter for Rails 4 to talk to a SQL Server DB. This adapter requires the tiny_tds gem. In order to install tiny_tds, you need freetds installed on your system because it's used during the compiling for the gem.
On my system I have installed RVM and homebrew. I have brew install freetds and confirmed that it works by tsql -C and have actually connected to the SQL Server. From my understanding, that means freetds is "installed" on my machine and works.
However, everytime I do a gem install tiny_tds if complains about freetds is missing
I have tried several of the parameter options to "link" to the proper files, but nothing seems to work for me. I've already spent several hours googling and looking over the gem author's writings. Some other developers I'm working with have this functioning, but I'm setting up a new environment and for some reason can't get it working. They've already looked into it as well and are not sure what the issue is.
It seems that the installation of the tiny_tds gem just doesn't know that freetds is actually installed on the system.
On a sidenote, I've also looked at mini_portile and it didn't work properly either...since I've already spent several hours down the current path, I want to figure this out before I switch over to investigating mini_portile.
Here's the output of the install:
$ gem install tiny_tds
Building native extensions. This could take a while...
ERROR: Error installing tiny_tds:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for sybfront.h... yes
checking for sybdb.h... yes
checking for tdsdbopen() in -lsybdb... no
-----
freetds is missing.
-----
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--enable-lookup
--disable-lookup
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/
--with-freetds-dir
--without-freetds-dir
--with-freetds-include
--without-freetds-include=${freetds-dir}/include
--with-freetds-lib
--without-freetds-lib=${freetds-dir}/
--with-iconvlib
--without-iconvlib
--with-sybdblib
--without-sybdblib
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/tiny_tds-0.6.2 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/tiny_tds-0.6.2/ext/tiny_tds/gem_make.out

Finally resolved this. Forgot to install Ruby via RVM after I installed RVM, and this was causing all the issues.
If you get weird errors similar to the above, do a rvm list to see if you even have any Rubies installed, and then do a which ruby on your terminal (Mac) to see if you are indeed using the RVM Ruby.

You can pass the location of the freetds lib to the gem command like this:
gem install tiny_tds -- --with-freetds-dir=/opt/homebrew/Cellar/freetds/1.2.21

Related

Bundler v2.0.2 refuses to install libxml-ruby 3.1.0 on Mac OS Catalina

I have found all of the answers of how to install libxml-ruby with the gem install command:
gem install libxml-ruby -v '3.1.0' -- --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include
Works beautifully! But then running this right afterward:
bundle install
gives the unhelpful error:
Fetching libxml-ruby 3.1.0
Installing libxml-ruby 3.1.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/me/myApp/code/myApp/.gems/ruby/2.6.0/gems/libxml-ruby-3.1.0/ext/libxml
/Users/me/.rbenv/versions/2.6.3/bin/ruby -I /Users/me/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20191215-25200-16wtr3.rb extconf.rb --with-xml2-config\=/usr/local/opt/libxml2/bin/xml2-config\
--with-xml2-dir\=/usr/local/opt/libxml2\ --with-xml2-lib\=/usr/local/opt/libxml2/lib\ --with-xml2-include\=/usr/local/opt/libxml2/include
/Users/me/.rbenv/versions/2.6.3/bin/ruby: warning: shebang line ending with \r may cause problems
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... *** 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=/Users/me/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
--with-xml2-config
OK, it looks like the libxml2 options are not being included in the call the bundler uses to install. So let's do this:
bundle config build.libxml-ruby --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include
That should work, right? Well no it doesn't. I am dead in the water until I can get Bundler to do what it is supposed to do.
There is no good answer for why Bundler fails here. The gem install line works. Bundler fails.
Inside the mkmf.log file is this:
find_header: checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... -------------------- no
And then several failures that all relate to not being able to find that header file.
It's looking in /opt/, instead of /usr/local/opt. I don't know how to make Bundler look in the correct place if it won't respect the bundle config commands.
Since Bundler wouldn't honor the paths I was passing in, I looked at the paths where it was looking for xmlversion.h.
I went into /usr/local/include. That's where all my Homebrew links are. I created a symlink to the Mac OS-provided libxml directory:
ln -s /usr/local/opt/libxml2/include/libxml2/libxml libxml
/usr/local/opt seems like a strange place for a system directory, but I'm tired of messing with it.
Once I did this, and went back into my app directory, bundle install worked. Well, I mean it broke again but it was on therubyracer this time. So it at least jumped this hurdle.

Ruby sqlite3 gem installation issue on Windows 10

I am very new to ruby and rails. I am trying to install to sqlite3 for trying a tutorial and having issues. I am on Windows 10 and using ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32].
Here is the installation error I am getting while running gem install sqlite3-ruby. I have also tried running gem install sqlite3 --platform=ruby -- --with-sqlite3-include=c:/sqlite3/include --with-sqlite3-lib=c:/sqlite3/lib
C:/Ruby26-x64/bin/ruby.exe -I C:/Ruby26-x64/lib/ruby/2.6.0 -r ./siteconf20190217-3116-1d59gcv.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.
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:/Ruby26-x64/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
--with-pthreadlib
--without-pthreadlib
--with-dllib
--without-dllib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/Ruby26-x64/lib/ruby/gems/2.6.0/extensions/x64-mingw32/2.6.0/sqlite3-1.4.0/mkmf.log
extconf failed, exit code 1
I have downloaded sqlite3 from their site and here is the folder structure of C:\sqlite3\
sqldiff.exe
sqlite3.exe
sqlite3_analyzer.exe
include\shell.c
include\sqlite3.c
include\sqlite3.h
include\sqlite3ext.h
lib\sqlite3.def
lib\sqlite3.dll
I have also copied sqldiff.exe, sqlite3.exe and sqlite3_analyzer.exe to C:\Ruby26-x64\bin.
In my environment variable, I have added C:\sqlite3\ to PATH and also created a new environment variable sqlite3-dir pointing to C:\sqlite3\
Could someone please provide some help for this installation problem?
adding gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec" in the project Gemfile file works. After that run bundle install. Make sure to install git in the machine. This is the github link
For solving this issue for all the projects I downloaded the gem file from https://rubygems.org/ and saved it locally, installed MinGW by cmd
C:\Sites>ridk exec pacman -S mingw-w64-x86_64-dlfcn
and the SQLite 3 gem after
C:\Sites>gem install --local C:\sqlite3-1.4.0.gem
and it worked for all the next projects created on Sites folder if you need to fix a project already created trying running bundle install again after those lines.
I also tried including the SQLite 3 files to the path but it didn't work for me either
This is what has currently worked for me and it's a per project fix; Samiul Alam Anik's answer, but with an addition. After you follow those steps, you might get a requires Bundler 2 and this is solved for me with gem update --system thanks to this GitHub ticket.
Make sure you have current Ruby version installed on your computer, install node ja, install yarn, update npm, update gem Ruby.
C:\Users\adilkemo>ruby --version
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x64-mingw32]
C:\Users\adilkemo>gem --version
3.2.15
C:\Users\adilkemo>node --version
v16.4.2
C:\Users\adilkemo>yarn --version
1.22.10
C:\Users\adilkemo>npm --version
7.18.1
C:\Users\adilkemo>sqlite3 --version
3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5
C:\Users\adilkemo>gem install rails
C:\Users\adilkemo>rails --version
Rails 6.1.4
C:\Users\adilkemo>cd Desktop
C:\Users\adilkemo\Desktop>rails new blog
C:\Users\adilkemo\Desktop>cd blog
C:\Users\adilkemo\Desktop\blog>bin/rails server - Goodbye!
Exiting
Terminate batch job (Y/N)? y
C:\Users\adilkemo\Desktop\blog>
https://rubyinstaller.org/
https://guides.rubygems.org/rubygems-basics/
https://nodejs.org/en/
https://classic.yarnpkg.com/en/docs/install/#windows-stable
https://www.sqlite.org/download.html
https://guides.rubyonrails.org/v5.0/getting_started.html

Unable to install tiny_tds on Mac OS X Yosemite v10.10.2

I am using RubyMine IDE on MAC OS X yosemite. On trying to install tiny_tds its giving the following error
sudo gem install tiny_tds -v '0.6.2'
Building native extensions. This could take a while...
ERROR: Error installing tiny_tds:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for sybfront.h... yes
checking for sybdb.h... yes
checking for tdsdbopen() in -lsybdb... no
freetds is missing.
* 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--enable-lookup
--disable-lookup
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/
--with-freetds-dir
--without-freetds-dir
--with-freetds-include
--without-freetds-include=${freetds-dir}/include
--with-freetds-lib
--without-freetds-lib=${freetds-dir}/
--with-iconvlib
--without-iconvlib
--with-sybdblib
--without-sybdblib
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/tiny_tds-0.6.2 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/tiny_tds-0.6.2/ext/tiny_tds/gem_make.out
I have installed freetds
brew install freetds
and I can see it when I do brew list
but again when I do sudo gem install tiny_tds , it gives me error as freetds missing.
Please help.
Thanks
Did gem install tiny_tds not work?
FYI - Using sudo with gem install is not best practice.
As I posted at Homebrew / TinyTDS / FreeTDS bundle error, in addition to brew install freetds, you may also need to tell the gem where to find freetds.
If you are using bundler, you can do that by configuring bundler.
For example (depending where exactly homebrew installed freetds):
bundle config set --global build.tiny_tds --with-freetds-dir=/opt/homebrew/Cellar/freetds/1.3.3

rbenv not setting the ruby version correctly

I installed rbenv successfully and this appears correct:
piousboxs-MacBook-Pro:lms piousbox$ cat .rbenv-version
1.8.7-p374
piousboxs-MacBook-Pro:lms piousbox$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin12.2.1]
piousboxs-MacBook-Pro:lms piousbox$ which ruby
/Users/piousbox/.rbenv/shims/ruby
But when I run bundle, it uses the system ruby somehow?
Installing tiny_tds (0.5.1)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for sybfront.h... no
-----
freetds is missing.
-----
*** 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.
Can anyone help?
Make sure you install and select a version of Ruby to use; rbenv defaults to the system one, even if you've used rbenv install to add another.
To see which Ruby rbenv is going to use, just run rbenv version.
See rbenv local or rbenv global or rbenv shell for details on how to set the version of Ruby in different contexts.
Emil Sit, the problem is that somehow freetds tries to use the system ruby, even though rbenv is configured correctly. There is this --ruby flag being passed when building native extensions:
Installing tiny_tds (0.5.1)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --ruby=/Users/piousbox/.rbenv/shims/ruby
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for sybfront.h... yes
checking for sybdb.h... yes
checking for tdsdbopen() in -lsybdb... no
-----
freetds is missing.
-----
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
--enable-lookup
--disable-lookup
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-freetds-dir
--without-freetds-dir
--with-freetds-include
--without-freetds-include=${freetds-dir}/include
--with-freetds-lib
--without-freetds-lib=${freetds-dir}/lib
--with-iconvlib
--without-iconvlib
--with-sybdblib
--without-sybdblib
Gem files will remain installed in /Users/piousbox/.bundler/tmp/26769/gems/tiny_tds-0.5.1 for inspection.
Results logged to /Users/piousbox/.bundler/tmp/26769/gems/tiny_tds-0.5.1/ext/tiny_tds/gem_make.out
An error occurred while installing tiny_tds (0.5.1), and Bundler cannot continue.
Make sure that `gem install tiny_tds -v '0.5.1'` succeeds before bundling.
Make sure you've run rbenv rehash after installing bundler with gem install bundler.
The solution was to remove the system-provided bundler from /usr/local/bundle, as it is outdated and does not run very well. With my new ruby (via rbenv) and bundler (via new ruby) I was able to compile everything correctly.

bundle install doesn't work on with RVM

I have a problem installing my bundle.
These were my last steps:
git clone http:...
git checkout -b daniel
bundle install
The error I got was:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native
extension.
/Users/daniel/.rvm/rubies/ruby-1.9.3-p286/bin/ruby extconf.rb checking for main() in -lpthread... yes checking for main() in
-lobjc... yes
*** 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=/Users/daniel/.rvm/rubies/ruby-1.9.3-p286/bin/ruby
--with-pthreadlib --without-pthreadlib --with-objclib
--without-objclib --enable-debug --disable-debug
/Users/daniel/.rvm/gems/ruby-1.9.3-p286/gems/therubyracer-0.11.0/ext/v8/build.rb:50:in
`build_with_rubygem_libv8': undefined local variable or method
`libv8_include_flags' for main:Object (NameError) from
extconf.rb:20:in `<main>'
Gem files will remain installed in
/Users/daniel/.rvm/gems/ruby-1.9.3-p286/gems/therubyracer-0.11.0 for
inspection. Results logged to
/Users/daniel/.rvm/gems/ruby-1.9.3-p286/gems/therubyracer-0.11.0/ext/v8/gem_make.out
An error occurred while installing therubyracer (0.11.0), and Bundler
cannot continue. Make sure that `gem install therubyracer -v '0.11.0'`
succeeds before bundling.
When I tried to run gem install therubyracer -v '0.11.0' I got:
Building native extensions. This could take a while... ERROR: Error
installing therubyracer: ERROR: Failed to build gem native extension.
/Users/daniel/.rvm/rubies/ruby-1.9.3-p286/bin/ruby extconf.rb checking for main() in -lpthread... yes checking for main() in
-lobjc... yes
*** 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=/Users/daniel/.rvm/rubies/ruby-1.9.3-p286/bin/ruby
--with-pthreadlib --without-pthreadlib --with-objclib
--without-objclib --enable-debug --disable-debug
/Users/daniel/.rvm/gems/ruby-1.9.3-p286/gems/therubyracer-0.11.0/ext/v8/build.rb:50:in
`build_with_rubygem_libv8': undefined local variable or method
`libv8_include_flags' for main:Object (NameError) from
extconf.rb:20:in `<main>'
Gem files will remain installed in
/Users/daniel/.rvm/gems/ruby-1.9.3-p286/gems/therubyracer-0.11.0 for
inspection. Results logged to
/Users/daniel/.rvm/gems/ruby-1.9.3-p286/gems/therubyracer-0.11.0/ext/v8/gem_make.out
I am working on Mac OS 10.7.5. Xcode and its command line tools and Rails are up to date.
SQLite 3 is also installed.
Can anyone help me?
EDIT:
I also tried to delete the repository and to clone it again, with the same errors.
EDIT:
Is the installation path of Rails and Sqlite3 correct?
daniel:~
daniel$ sudo gem update --system Latest version currently
installed. Aborting.
daniel:~
daniel$ sudo gem install rails
Fetching:
rails-3.2.11.gem (100%) Successfully installed
rails-3.2.11 1 gem installed
Installing ri documentation for rails-3.2.11...
Installing RDoc documentation for rails-3.2.11...
daniel:~
daniel$ sudo gem install sqlite3
Fetching: sqlite3-1.3.7.gem (100%)
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.7 1 gem installed
Installing ri documentation for sqlite3-1.3.7...
Installing RDoc documentation for sqlite3-1.3.7...
daniel:~
daniel$ which ruby irb gem rake
/Users/daniel/.rvm/rubies/ruby-1.9.3-p286/bin/ruby
/Users/daniel/.rvm/rubies/ruby-1.9.3-p286/bin/irb
/Users/daniel/.rvm/rubies/ruby-1.9.3-p286/bin/gem
/Users/daniel/.rvm/gems/ruby-1.9.3-p286/bin/rake
At least one problem is that you are running RVM, but used sudo to install gems on your system.
Read "RVM and RubyGems", especially the part that says:
"DO NOT use sudo..."
RVM creates a sandbox for you, the user, in your own user-space on a machine, that allows you to manage it without needing to be the system administrator. In other words, that means you don't have to use sudo for any RVM or gems management.
If you do use sudo, you temporarily cease being you, the user, and become the administrator, with administrator privileges and the administrator's environment, which does NOT include the RVM sandbox in your /Users/daniel/.rvm/rubies/ruby-1.9.3-p286 path. Knowledge of the sandbox is carried by the PATH in your environment, which the root on your machine doesn't use. Gems installed inside that sudo sub-shell get installed into the location that the administrator account knows about, which is inside the System Ruby installation, which is why your RVM sandboxed Ruby doesn't see them: There is no crossover between the System's Ruby and your RVM-controlled RUby. That's the whole idea of a sandbox: separation of the elements and resources to avoid contamination.
You could have figured this all out by looking at the output of:
which ruby irb gem rake
The path for all of them is pointing to your sandbox:
/Users/daniel/.rvm/rubies
On a Mac OS system, that command should have reported:
/usr/bin/ruby
/usr/bin/irb
/usr/bin/gem
/usr/bin/rake
Reinstall Rails and the SQLite gem using:
gem install rails sqlite3
and see how your bundle behaves.
And, by the way, do NOT use sudo to deliberately try to manage/delete the System installed Ruby. That was installed by Apple for their own purposes, to enable software they installed. It's OK to take advantage of its existence, but it's there for their use. Use a RVM-managed Ruby for your own purposes.

Resources