Error while installing json gem 'mkmf.rb can't find header files for ruby'
Modern era update, as stated by mimoralea:
In case that you are using ruby 2.0 or 2.2 (thanks @patrick-davey).
sudo apt-get install ruby2.0-dev
sudo apt-get install ruby2.2-dev
sudo apt-get install ruby2.3-dev
or, generic way:
sudo apt-get install ruby-dev
or
sudo apt-get install ruby`ruby -e 'puts RUBY_VERSION[/\d+\.\d+/]'`-dev
The first link you’ve posted is exactly your case: there is no ruby development environment installed. Development env is needed to compile ruby extensions, which are mostly written in C
. Proxy has nothing to do with the problem: everything is downloaded fine, just compilation fails.
I would suggest you to install ruby-dev
(ruby-devel
for rpm-based distros) package onto you target machine.
gcc
package might be needed as well.
Try:
$ sudo apt-get install ruby-dev
Or, for Redhat distro:
$ sudo yum install ruby-devel
Or, for [open]SuSE:
$ sudo zypper install ruby-devel
gem install cannot find a header file
The answer to this question was answered by the gem author via email, but I'd like to share the solution.
sudo env ARCHFLAGS="-arch x86_64" gem install talib_ruby -- --with-talib-include=/opt/local/var/macports/software/ta-lib/0.4.0_0/opt/local/include/ta-lib --with-talib-lib=/opt/local/var/macports/software/ta-lib/0.4.0_0/opt/local/lib
It is important to note that this gem is also not compatible with Ruby 1.9.2. From what the error list generated, it had some issues with the definition of struct RObject (fill in Object with String, Array, etc), which I traced to the ruby.h header file. If you'd like to use this gem, you can install rvm and then type
rvm install ruby-1.8.7 --with-readline-dir=/opt/local
From there, simply follow the guidance from the gem author with the input listed above.
UPDATE: the gem author has made talib_ruby compatible with 1.9.x so there is no longer a need to install 1.8.7
gem install: Failed to build gem native extension (can't find header files)
For those who may be confused by the accepted answer, as I was, you also need to have the ruby headers installed [ruby-devel].
The article that saved my hide is here.
And this is the revised solution (note that I'm on Fedora 13):
yum -y install gcc mysql-devel ruby-devel rubygems
gem install -y mysql -- --with-mysql-config=/usr/bin/mysql_config
For Debian, and other distributions using Debian style packaging the ruby development headers are installed by:
sudo apt-get install ruby-dev
For Ubuntu the ruby development headers are installed by:
sudo apt-get install ruby-all-dev
If you are using a earlier version of ruby (such as 2.2), then you will need to run:
sudo apt-get install ruby2.2-dev
(where 2.2 is your desired Ruby version)
Error: Failed to build gem native extension (can't find header files for ruby.h)
Well I suspect you actually need ruby2.4-dev if you're using ruby 2.4. But I'd recommend not using system ruby and installing gems globally with sudo
in the first place. Using a ruby environment manager such as rbenv is the best way to avoid dependency hell. Here's a good overview of the available options: http://kgrz.io/programmers-guide-to-choosing-ruby-version-manager.html
Failing installing pg gem, mkmf.rb can't find header files for ruby (Mac OSX 10.6.5)
Generally the gem bundles for Postgres want to know where pg_config
is hiding so they can ask about the Postgres installation.
Use locate pg_config
to see if your Mac knows where it's hiding.
I installed a copy of Postgres using mappstack, so my Mac says there's a copy at:
/Applications/mappstack-1.2-3/postgresql/bin/pg_config
and another at:
/Library/PostgreSQL/9.0/bin/pg_config
I don't remember installing the one at /Library/PostgreSQL/9.0
, so it might have been preinstalled by Snow Leopard, or I did it when under the influence of too much work, possibly using the Postgres installer from EnterpriseDB.
Once you've found the location of pg_config
try adding that directory to the start of your PATH and then rerun the gem install.
Or use:
export SQL_PATH=/Library/PostgreSQL/9.0
gem install pg -- --with-pg-config=$SQL_PATH/bin/pg_config
and try installing. If either of those work you're done. Otherwise...
The next thing the installers might want are access to the Postgres headers, so you look in the parent of the bin
directories, and see if you can find an include
directory.
After that, look in that directory for a lib
directory. Once you know those locations you should have all you need to set your environment variables to let the installer complete. You'll need to read the README
or INSTALL
file of the installer and see what needs to be set up. You'll be configuring:
export include_dir=$SQL_PATH/include/
export lib_dir=$SQL_PATH/lib/
gem install pg -- --with-pgsql-include-dir=$include_dir --with-pgsql-lib-dir=$lib_dir
Hopefully that'll all help. I have Rails 3 and my Postgres running fine, using the mappstack Postgres and the EnterpriseDB versions, so the above info should get you there.
Can't find header files while running bundle install
Paths suggest you are using a Mac, right? Maybe this answer solves your problem?
gem install mysql failure in Snow Leopard
Error looks the same. Accepted answer said that "Installing the Xcode that's bundled with the Snow Leopard fixed the problem."
Can't find header files for Ruby on SUSE?
For those with similar issues I got this working by.
Uninsalling ruby and rvm
Building zlib from source with the shared option
./configure --shared
make
make install
I did the same for Ruby and that worked.
I could not get any RPM, Zypper, RVM installers to install properly. In each case they all seemed to have issues with zlib ?
Docker for Mac - mkmf.rb can't find header files for ruby
For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license with
sudo xcode-select --install
sudo xcodebuild -license accept
The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by running
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
which on macOS 10.14 with Xcode 11 prints the non-existent path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk
. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:
sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
This should now correctly print
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
Likewise, gem install
should work while that SDK is selected.
To switch back to using the current Xcode 11 SDK, use
sudo xcode-select --switch /Applications/Xcode.app
Related Topics
How to Do String Comparison in Ruby
How to Get Long Filename from Argv
How to Preload Concerns in a Rails Initializer Using Rails 6/Zeitwerk
Rails 3.1 Load CSS in Particular Order
How to Use Reference Images in SASS When Using Rails 3.1
Regular Expression "Empty Range in Char Class Error"
Why Is This Not a Syntax Error
Best Way to Use Twitter Bootstrap Icons as Links in Ruby on Rails 3
Twitter Bootstrap Displays Button with Greyed Text
R Statistical Package Gem for a Rails Application
Rails/Ruby Error When Creating Database: Unable to Load the Eventmachine C Extension
Can't Convert String into Integer in Ruby/Ruby-On-Rails
How to Format a Date to Mm/Dd/Yyyy in Ruby
Error When Run Migrations on Heroku, Postgresql with Rails 5
Delete Contents of Array Based on a Set of Indexes
In Ruby How to Use Class Level Local Variable? (A Ruby Newbie's Question)