169

this question is for Windows

I tried installing the gem 'sinatra-websocket', but when I ran gem install sinatra-websocket, I got this error...

ERROR: Failed to build gem native extension

... along with ...

C:/Ruby193/bin/ruby.exe extconf.rb checking for main() in -lc... *** 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:/Ruby193/bin/ruby --with-thin_parser-dir --without-thin_parser-dir --with-thin_parser-include --without-thin_parser-include=${thin_parser-dir}/include --with-thin_parser-lib --without-thin_parser-lib=${thin_parser-dir}/lib --with-clib --without-clib C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:476:in `try_link' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:619:in `try_func' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:845:in `block in have_library' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:254:in `open' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:280:in `postpone' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for' from C:/Ruby193/lib/ruby/1.9.1/mkmf.rb:840:in `have_library' from extconf.rb:4:in `<main>' 

Here's what the mkmf file in C:\Ruby193\lib\ruby\gems\1.9.1\gems\thin-1.6.3\ext\thin_parser looks like:

"gcc -o conftest -IC:/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Ruby193/include/ruby-1.9.1 -I. -DFD_SETSIZE=2048 -DFD_SETSIZE=2048 -O3 -fno-omit-frame-pointer -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -LC:/Ruby193/lib -L. -march=i486 -lmsvcrt-ruby191 -lshell32 -lws2_32 -limagehlp -lshlwapi " checked program was: /* begin */ 1: #include "ruby.h" 2: 3: #include <winsock2.h> 4: #include <windows.h> 5: int main(int argc, char **argv) 6: { 7: return 0; 8: } /* end */ 

I'm using Windows 7.

Why am I getting the error? There's a line stating "could not create Makefile...", but is that relevant?

8
  • The mkmf.log file can be found under the gem's installation directory. Commented Jan 4, 2015 at 18:02
  • @siaw23 I've added the contents of the file Commented Jan 4, 2015 at 18:45
  • 1
    The one I've used in the past is Mingw. From this you can try make -v and gcc -v to check. You might try installing the Ruby dev kit Commented Jan 8, 2015 at 0:25
  • 2
    Check this answer out, it's detailed and better than any advice I could give. stackoverflow.com/a/11484346/335847 Commented Jan 8, 2015 at 0:26
  • 1
    if you are getting this on a Mac when running bundle install--- for example, for puma 5.6.2, I have made a separate SO post because this one is specific to Windows (as well there is no XCode on windows so all these XCode answers are very confusing) stackoverflow.com/questions/71383295/… Commented Mar 7, 2022 at 18:10

21 Answers 21

213

Also for Mac:

if you do not already have xcode dev tools installed on your system (perhaps you recently upgraded your OS or Xcode), run xcode-select --install

otherwise, a more invasive fix is to set the active directory using the --switch flag

sudo xcode-select --switch /

from the xcode-select manual:

 -s <path>, --switch <path> Sets the active developer directory to the given path, for example /Applications/Xcode-beta.app. This command must be run with superuser permissions (see sudo(8)), and will affect all users on the system. To set the path without superuser permissions or only for the current shell session, use the DEVELOPER_DIR environment variable instead (see ENVIRONMENT). 

If you already have Xcode installed, you may have a different problem, in which case, see this post Installing puma 5.6.2 with native extensions Gem::Ext::BuildError: ERROR: Failed to build

Sign up to request clarification or add additional context in comments.

11 Comments

I already had command line tools installed, and this worked for me also. Thanks!
Did not help me
xcode-select: error: invalid developer directory '/' i got this error
Wow this worked for me. Thank you! (installing a Cococpods plugin - github.com/joncardasis/cocoapods-user-defined-build-types). Also curious why this fixes the issue!
This answer needs more of an explanation. The fact that it A) requires sudo, B) I don't know what xcode is, and C) looks to operate on the root folder are three huge red flags for a novice.
|
70

I was having this issue on MacOS Mojave(10.14.1). Installing latest ruby via Homebrew and setting some env variables solved it for me:

(copied from brew info ruby instructions)

export PATH="/usr/local/opt/ruby/bin:$PATH" export LDFLAGS="-L/usr/local/opt/ruby/lib" export CPPFLAGS="-I/usr/local/opt/ruby/include" export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig" 

7 Comments

If you installed ruby via brew, you can get those env variables with brew info ruby
This answer fixed my issue when trying to use the Sass compiler after the recent OSX update
This worked for a failing inspec installation
works for Catalina 10.15.7, many thanks.
Worked for Big Sur 11.6.5, thanks.
|
67

For a Mac:

Have you run:

xcode-select --install 

To install the Xcode Developer tools?

8 Comments

I don't think the "development tools" being referenced in the error has anything to do with xcode, especially considering this is on Windows.
The original question definitely stated Windows, but regardless - this helped me on a Mac!
Just what I was missing on OSX El Capitan.
'xcode-select' is not recognized as an internal or external command, operable program or batch file.
(On Mac OSx Mojave) After running xcode-select --install, close and re-open the terminal. Then, run sudo xcodebuild -license, follow the instructions and finally accept the license agreement. In my experiment, this was the solution to solve the problem.
|
57

I ran into this same problem on Ubuntu 18.04. The fix on Ubuntu was to install the ubuntu-dev-tools package:

$ sudo apt-get install ubuntu-dev-tools 

4 Comments

thank you, works for me! on Ubuntu 20.04
Thank you. I struggled with this for a while on 20.04 also
I'm working on docker and host machine is ubuntu as container is. This worked very well for me, thank you mate.
I searched for a lot of different solutions, this fixed it as make was missing.
27

edit: rubyinstaller now provides installs with the devkit included. These are labelled on the download page.

Sounds like you're missing the devtools for ruby.

You can get them here: http://rubyinstaller.org/downloads/ just scroll down to "Development Kit".

Download and extract that to anywhere you want. Open up the folder in command prompt and run ruby dk.rb init. This will create a config file detailing your ruby installations. Check this config file before continuing to confirm the paths to your ruby installation are correct.

Now run ruby dk.rb install. This will install the development kit.

Restart command prompt, and try to install the gem again.

Comments

26

Tried all previous answers but none worked.

Did this instead:

brew install cocoapods 

3 Comments

Worked for me as well. I struggled with The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. for some time.
I'm a Mac user and have Xcode running. This works for me.
This installed ruby for me, and also libyaml. Could be one of those two were the original culprit. (I had ruby 2.x.x, it installed ruby 3.1.2)
18

If you're on Mac and recently upgraded your Xcode tools, run the following commands:

sudo xcode-select --install sudo xcodebuild -license 

1 Comment

I was able to execute your steps without error on Mojave, but they didn't help me with the error "You have to install development tools first".
18

My issue was that I updated to macOS Big Sur, and somehow, the command line tools were outdated.

I know this because, when I tried to run brew install rbenv, I received this error:

Error: Your Command Line Tools (CLT) does not support macOS 11. It is either outdated or was modified. Please update your Command Line Tools (CLT) or delete it if no updates are available. Update them from Software Update in System Preferences or run: softwareupdate --all --install --force If that doesn't show you any updates, run: sudo rm -rf /Library/Developer/CommandLineTools sudo xcode-select --install Alternatively, manually download them from: https://developer.apple.com/download/more/. 

So I ran

sudo rm -rf /Library/Developer/CommandLineTools sudo xcode-select --install 

and after it finished, the gem installed successfully.

2 Comments

This worked just fine without the removal of the CommandLineTools directory 👌 Thanks!
Thank you this helped me install cocoa pods on m1 Mac mini.
8

If you're on Mac OS 10.14 (Mojave) try

cd /Library/Developer/CommandLineTools/Packages/; open macOS_SDK_headers_for_macOS_10.14.pkg 

Credit to Roy Huang Reference: https://stackoverflow.com/a/55732339/1598551

1 Comment

I was able to execute your steps without error on Mojave, but they didn't help me with the error "You have to install development tools first".
7

This solution saved me:

  1. Install homebrew via terminal.

  2. After homebrew is successfully installed, type in the terminal

    '$ brew install cocoapods'

And Finally Done!

update: You can install homebrew by this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

from here

3 Comments

Plz elaborate on how to install homebrew via terminal! Step by step, plz.
Anyway, it did it! 😃 (I used the command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" from: brew.sh . Feel free to put that in your answer!)
@KarolinaHagegård Thanks, I added it to the answer.
5

Here is my solution for mac OSX:

In the Terminal App:

Step 1: Make sure you have installed the Xcode developer tool by the following script:

xcode-select --install

Step 2: Upgrade your ruby by the script:

brew install ruby

Step 3: Try again.

1 Comment

I tryed anything on the earch, more that two days, I am in MacOS 10.15.7 catalina, xcode 12.3, trying to develop nativescript apps, and finallay this solution worked for me and cocoapods installed successfully. thanks man.
4

This means you don't have compiler tools installed. For mac xcode-select --install installs them. For linux or other systems you can use package managers, for example apt install cmake should install the necessary build tools for systems having apt package manager.

Comments

3

Actually, the real problem is when one upgrades from a major version of macOS to another and installs a newer Xcode.

cd /Library/Developer/CommandLineTools ls -l SDKs/ total 0 lrwxr-xr-x 1 root wheel 14 Feb 4 21:41 MacOSX.sdk -> MacOSX11.1.sdk drwxr-xr-x 8 root wheel 256 Feb 4 21:43 MacOSX10.15.sdk drwxr-xr-x 7 root wheel 224 Feb 4 21:43 MacOSX11.1.sdk 

After going to Apple's developer site and downloading the CLI tools by hand, this is what the folder contains:

$> ls -l SDKs/ lrwxr-xr-x 1 root wheel 14 May 4 18:10 MacOSX.sdk -> MacOSX11.3.sdk drwxr-xr-x 8 root wheel 256 May 4 18:10 MacOSX10.15.sdk drwxr-xr-x 7 root wheel 224 Feb 4 21:43 MacOSX11.1.sdk drwxr-xr-x 7 root wheel 224 Mar 16 10:03 MacOSX11.3.sdk lrwxr-xr-x 1 root wheel 14 May 4 18:09 MacOSX11.sdk -> MacOSX11.3.sdk 

You might still need to reset your Xcode with:

$> sudo xcode-select --reset $> sudo xcodebuild -license 

Verify with:

$> sudo xcode-select --print-path /Applications/Xcode.app/Contents/Developer 

Lastly, if you still see errors compiling something, you will need to pay close attention to what the compiler error is and address it. For example, in my case, it was simply that in macOS Big Sur clang needs special arguments to add declarations (struct). It was fixed with:

export CFLAGS="-fdeclspec $CFLAGS" 

This was the error if you're curious (or anybody looking for an answer for Ruby 3.0.x online):

/usr/local/Cellar/ruby/3.0.1/include/ruby-3.0.0/ruby/internal/fl_type.h:285:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes 

Comments

2

I had recently upgraded to MAC OS big sur, and started getting the error when running gem install...

Solution is to remove the CLT completely and run the installation again.

Optional :

brew upgrade

Run :

sudo rm -rf /Library/Developer/CommandLineTools

sudo xcode-select --install

Comments

2

For Ubuntu 20.04.3 LTS (Focal Fossa) -- WSL

There are some dependencies to solve before, try with following sequence of commands:

# if ERROR: 'Gem installation error: You have to install development tools first' # BEFORE installing the dev-tools, install dependencies: # if ERROR: 'GCC fatal error: stdio.h: No such file or directory' $ sudo apt-get install libc6 # https://stackoverflow.com/a/20150282/5078874 $ sudo apt-get install libc6-dev $ sudo apt-get install libffi-dev # Now, go for the development tools # https://stackoverflow.com/a/63442072/5078874 $ sudo apt-get install ubuntu-dev-tools # Finally, try again $ bundle update --bundler # ... enjoy :) 

References:

Comments

2

This is works for my Mac.

brew install cocoapods 

Comments

1

On Debian 12 you need to run

sudo apt install build-essential ruby-dev

Comments

0

If you have multiple versions of Xcode installed, make sure you select the command line tools from the most recent one, otherwise gem will not be able to find them.

Comments

0

On macOS Catalina; After running $ brew install coreutils (credit) –– I followed an older article by Evan Hoffman, installing chef ( which embeds latest stable release of Ruby )

$ curl -L https://www.getchef.com/chef/install.sh | sudo bash

Then I can install any gems needed, with all the requisite development tools now installed;

$ sudo gem install -V <gem>

Your mileage may vary on Big Sur

Comments

0

In Mac, for me worked by doing a:

sudo xcode-select --reset 

I had xcode-select previously installed, but it was not working anyway. Doing a --reset fixed this for me.

Comments

0

In Fedora I solved it by installing ruby-devel:

sudo dnf install ruby-devel 

1 Comment

This question is specifically about Windows

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.