Error: Failed to Build Gem Native Extension on Windows

ERROR: Failed to build gem native extension on Windows

Finally after much research I found the culprit was the RubyGems version incompatibility with native extension gems!!!

I had ruby gems ver 2.4.1 but seems like >2.4.0 has these issues

gem update --system 2.3.0 did the trick for me :)

Refer: https://github.com/rubygems/rubygems/issues/977

Gem::Ext::BuildError: ERROR: Failed to build gem native extension - Rails 4

I just ran into the same error while doing a bundle install. Turns out it's a known issue, but the fix isn't due out until RubyGems 2.5. In the meantime, downgrading to v2.3.0 should be a suitable workaround:

> gem update --system 2.3.0

ruby install rails with Error ---Failed to build gem native extension.(Windows platform)

Just back from a vacation, and this problem has been solved during the holiday. Forgive me for not remembering to close this issue until now.XD

With the help of Josien's comments, the problem has narrowed down to gem install websocket-driver failed. It's easier to find this problem on stackoverflow-Error when trying to install gem websocket-driver-0.7.3

Finally, I solved this problem just by typing ridk install (to make MSYS2 work for ruby3.0.1)——I have installed MSYS2 and make it work under ruby2.7.4, but if you want to make it work for ruby3.0.1 samely , you need to excute this command under ruby3.0.1.

After installed MSYS2 for ruby3.0.1, rails installed sucessfully.

C:\Users\Administrator>Uru ls
274p191 : ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32]
310p0 : ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]

C:\Users\Administrator>ruby -v
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]

C:\Users\Administrator>ridk install
_____ _ _____ _ _ _ ___
| __ \ | | |_ _| | | | | | |__ \
| |__) | _| |__ _ _ | | _ __ ___| |_ __ _| | | ___ _ __ ) |
| _ / | | | '_ \| | | | | | | '_ \/ __| __/ _` | | |/ _ \ '__/ /
| | \ \ |_| | |_) | |_| |_| |_| | | \__ \ || (_| | | | __/ | / /_
|_| \_\__,_|_.__/ \__, |_____|_| |_|___/\__\__,_|_|_|\___|_||____|
__/ | _
|___/ _|_ _ __ | | o __ _| _ _
| (_) | |^| | | |(_|(_)\^/_>

1 - MSYS2 base installation
2 - MSYS2 system update (optional)
3 - MSYS2 and MINGW development toolchain

Which components shall be installed? If unsure press ENTER [1,3] 1,3

> sh -lc true
MSYS2 seems to be properly installed
Install MSYS2 and MINGW development toolchain ...
> pacman -S --needed --noconfirm autoconf autogen automake-wrapper diffutils file
...
...
...
Install MSYS2 and MINGW development toolchain succeeded

1 - MSYS2 base installation
2 - MSYS2 system update (optional)
3 - MSYS2 and MINGW development toolchain

Which components shall be installed? If unsure press ENTER []

C:\Users\Administrator>gem install rails
Building native extensions. This could take a while...
Successfully installed websocket-driver-0.7.5
Building native extensions. This could take a while...
Successfully installed nio4r-2.5.8
Successfully installed actioncable-7.0.2
Successfully installed rails-7.0.2
Parsing documentation for websocket-driver-0.7.5
Installing ri documentation for websocket-driver-0.7.5
Parsing documentation for nio4r-2.5.8
Installing ri documentation for nio4r-2.5.8
Parsing documentation for actioncable-7.0.2
Installing ri documentation for actioncable-7.0.2
Parsing documentation for rails-7.0.2
Installing ri documentation for rails-7.0.2
Done installing documentation for websocket-driver, nio4r, actioncable, rails after 2 seconds
4 gems installed

C:\Users\Administrator>rails -v
Rails 7.0.2

installing rails fails, failed to build gem native extension

I fixed this issue by using wsl. The installation process is explained here. I also had to use this to enable wsl on windows 10 build 16299.192(settings > system > about). also after i installed everything I ran sudo apt-get install nodejs and gem install rails. After this, I could run the demo(wsl> rails new demo, wsl> cd demo, wsl> rails server).

Error installing jekyll: ERROR: Failed to build gem native extension

Although they made the Ruby+DevKit an "optional" download for the RubyInstaller on Windows, if you plan to install gems, it is practically a necessity. A large percentage of the most popular gems are C extension that will need built on your machine when being installed.

The DevKit is a handy toolchain that supplies everything you need for this to be done, automatically without you needed to do anything more than type gem install XXXXX. Without it, you either cannot use C extension gems, or must have already installed MSYS and MingW, have them configured properly, which is all not a user-friendly experience, even for those who familiar with the process.

So even if DevKit is optional, it is still required to make the most of Ruby on Windows.

gem error: Failed to build gem native extension

The specific error reason is contained in the message you posted, it's just a little bit hidden within the context:

make failedNo such file or directory - make

It seems your system doesn't have the make lib installed. A similar question had it solved by installing the whole MSYS2 and MINGW development toolchain:

ridk install

then options:

[1,3]

Windows Failed to build gem native extension when installing Squib

So it seems like the version of glib2 that squib is calling for is not installing correctly on my Windows 10 system. After multiple attempts I discovered a work around that can get squib installed. It requires you to have a "subsystem for Linux" not as bad as it sounds, follow me:

1. Head to this site

2. Scroll down to the "Using the Windows Subsystem for Linux" section.

3. Follow all instructions after "Using the Windows Subsystem for Linux" and before "Bonus points!".

4. Once ruby is installed. Type the code below into your terminal:

sudo apt-get install -y build-essential

5. Once that is complete. Type the code below into your terminal:

sudo gem install squib

6. You will get through the majority of the installation and then you will get a "ERROR: Failed to build gem native extension." This is in reference to gdk_pixbuf2. Type the code below into your terminal:

sudo gem update rake

7. Finally, type the code below into your terminal:

sudo gem install squib

8. You are done and ready to use squib!

Having to update this rake file makes me think I should have updated the make file in my windows installation of ruby.

Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)

There are similar questions:

  • `require': no such file to load -- mkmf (LoadError)
  • Failed to build gem native extension (mkmf (LoadError)) - Ubuntu 12.04

Usually, the solution is:

sudo apt-get install ruby-dev

Or, if that doesn't work, depending on your ruby version, run something like:

sudo apt-get install ruby1.9.1-dev

Should fix your problem.


Still not working? Try the following after installing ruby-dev:

sudo apt-get install make


Related Topics



Leave a reply



Submit