rails6 tiny_tdsインストール時にエラー「An error occurred while installing tiny_tds (2.1.3), and Bundler cannot continue.」が発生

  • 作成日 2021.02.23
  • 更新日 2026.06.10
  • rails
rails6 tiny_tdsインストール時にエラー「An error occurred while installing tiny_tds (2.1.3), and Bundler cannot continue.」が発生

Rails6でtiny_tdsインストール時に「An error occurred while installing tiny_tds, and Bundler cannot continue」が発生した場合の対処法を解説します。FreeTDSの導入方法や依存パッケージの確認、bundle installの解決手順を紹介します。

環境

  • OS CentOS Linux release 7.9.2009 (Core)
  • Ruby 2.7.2
  • Rails 6.1.1
  • rbenv 1.1.2-40-g62d7798

エラー全文

Gemfileに以下を記述して「bundle install」実行時に発生

gem 'tiny_tds'

エラー全文

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

  /home/sampleuser/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/tiny_tds-2.1.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/sampleuser/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/tiny_tds-2.1.3 for inspection.
Results logged to /home/sampleuser/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/tiny_tds-2.1.3/gem_make.out

An error occurred while installing tiny_tds (2.1.3), and Bundler cannot continue.
Make sure that `gem install tiny_tds -v '2.1.3' --source 'https://rubygems.org/'` succeeds before bundling.

原因

sqlserverの開発ツールをインストールする必要があるようです。

対処法

インストールを行います。

sudo yum install freetds-devel

エラーの原因2

このエラーは、tiny_tdsのビルドに必要なFreeTDSや開発用ライブラリがインストールされていない場合に発生することが多いです。

An error occurred while installing tiny_tds (2.1.3),
and Bundler cannot continue.

FreeTDSをインストールする

CentOS系の場合は以下を実行します。

sudo yum install freetds freetds-devel -y

Ubuntuの場合は以下のコマンドを実行します。

sudo apt-get install freetds-dev freetds-bin -y

tiny_tds単体でインストールを試す

gem install tiny_tds -v 2.1.3

単体でインストールできるか確認することで、Bundler固有の問題か切り分けできます。

mkmf.logを確認する

ビルドに失敗した原因はmkmf.logに出力されます。

cat ~/.bundle/extensions/**/tiny_tds*/mkmf.log

「Failed! Do you have FreeTDS installed?」と表示される場合は、FreeTDSの導入漏れが原因です。

bundle installを再実行する

bundle install

依存関係の解消後に再度実行し、エラーが解消されるか確認しましょう。

参考リンク