You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu系统Chef Client安装tiny_tds gem原生扩展编译失败求助

Fixing "Failed to build gem native Extension" for tiny_tds in Chef Client on Ubuntu

Let's break down why this is happening first: when you run gem install tiny_tds manually, you're using your system's Ruby environment which can find the manually installed FreeTDS libraries. But Chef uses its own embedded Ruby runtime (located at /opt/chef/embedded/), which doesn't inherit the same library paths or environment variables as your system shell. That's why the gem build fails when Chef tries to install it—even though FreeTDS is on your system, Chef's embedded Ruby can't locate it.

Here's how to fix this in your cookbook:

Step 1: Install Required System Dependencies

First, make sure your cookbook installs the necessary build tools and FreeTDS development files. Instead of compiling FreeTDS manually (which works but adds complexity), you can use Ubuntu's official packages for simplicity:

package 'build-essential'
package 'freetds-dev'
package 'freetds-bin'

If you prefer to keep your manually compiled FreeTDS, skip these package resources but note the path where you installed it (/usr/local in your case).

Step 2: Install tiny_tds with Explicit FreeTDS Path

Use Chef's chef_gem resource (instead of relying solely on metadata.rb) to install tiny_tds, and explicitly tell the gem build process where to find FreeTDS. This ensures Chef's embedded Ruby uses the correct library paths.

Option 1: Using Ubuntu's official FreeTDS packages

chef_gem 'tiny_tds' do
  version '2.1.1' # Match the version you're trying to install
  options '--with-freetds-dir=/usr'
  action :install
end

Option 2: Using your manually compiled FreeTDS

If you want to stick with the manually built FreeTDS at /usr/local, use this instead:

chef_gem 'tiny_tds' do
  version '2.1.1'
  options '--with-freetds-dir=/usr/local'
  action :install
end

Why This Works

The --with-freetds-dir parameter tells the gem's extension build script exactly where to find the FreeTDS header files and libraries. Chef's embedded Ruby environment doesn't have /usr/local (or even /usr) in its default library search path for gem builds, so we have to explicitly point it there.

Verify the Fix

After updating your cookbook, run Chef Client again:

sudo chef-client -o "recipe[tiny_tds_cookbook]"

The gem should now build successfully because it can locate the FreeTDS dependencies through the explicit path we provided.

内容的提问来源于stack exchange,提问作者Yoda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:43:49