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

Viewed 1377

Newbie to Ruby, and just started rails journey.

Have searched stackoverflow but many these questions came too long ago. My English is not good, please bear with my description. Here's my situation, hope I make myself clearly.

I'm on windows. And when I took ruby lessons online I had installed an older envir-- ruby2.7.4 with rails 7.0.1.

Yesterday I want to finish a new project with a newer ruby envir-- so i installed ruby3.1.0, but when I tried to install rails for this new Ruby verison, the ERROR occurred.

here is my envir:

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>gem -v
3.3.6

C:\Users\Administrator>d:

D:\>cd RubyDevkit

D:\RubyDevkit>ruby dk.rb install
[INFO] Skipping existing gem override for 'D:/Ruby27-x64'
[WARN] Skipping existing DevKit helper library for 'D:/Ruby27-x64'
[INFO] Skipping existing gem override for 'D:/Ruby31-x64'
[WARN] Skipping existing DevKit helper library for 'D:/Ruby31-x64'

D:\RubyDevkit>

as you can see, my current ruby version is 3.1.0 and I think I have installed Devkit for both my Rubies successfully.

and I have intalled MSYS2 as well (although I dont know why ruby need it, but I have met another ERROR which remind me to install MSYS and add it to PATH) msys -Syu

I think I have done everything correctly before I met this ERROR:

C:\Users\Administrator>gem install rails
Building native extensions. This could take a while...
ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
D:/Ruby31-x64/bin/ruby.exe -I D:/Ruby31-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220128-11340-9w9ez5.rb extconf.rb
creating Makefile

current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\= clean
current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\=
make failedNo such file or directory - make

Gem files will remain installed in D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5 for inspection.
Results logged to D:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/websocket-driver-0.7.5/gem_make.out

There is no exceptions when I installed rails for ruby2.7.4(the same command just finished with no error or warning).

I cant find any similar situation online. Anyone could help?

-------------------01/29-----------------divide----------------------------

thank for comments, really thought-provking. Following some plans(Although failed) i tried to install gem websocket-driver separately, got the same error:

C:\Users\Administrator>gem install websocket-driver:0.7.5
Building native extensions. This could take a while...
ERROR:  Error installing websocket-driver:
        ERROR: Failed to build gem native extension.

    current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
D:/Ruby31-x64/bin/ruby.exe -I D:/Ruby31-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220129-3864-wqfhn2.rb extconf.rb
creating Makefile

current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\= clean
current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\=
make failedNo such file or directory - make

Gem files will remain installed in D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5 for inspection.
Results logged to D:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/websocket-driver-0.7.5/gem_make.out

(delete this gem from root directory and reInstall got the same result as well)

Then I tired got this gem form bundler.rubygems.org, and install it locally. Got the same error:

C:\Users\Administrator>d:

D:\>cd rubyDownloads

D:\rubyDownloads>gem install websocket-driver-0.7.5.gem --local
Building native extensions. This could take a while...
ERROR:  Error installing websocket-driver-0.7.5.gem:
        ERROR: Failed to build gem native extension.

    current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
D:/Ruby31-x64/bin/ruby.exe -I D:/Ruby31-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220129-5896-885p1m.rb extconf.rb
creating Makefile

current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\= clean
current directory: D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR\=
make failedNo such file or directory - make

Gem files will remain installed in D:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/websocket-driver-0.7.5 for inspection.
Results logged to D:/Ruby31-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/websocket-driver-0.7.5/gem_make.out

Now the problem becomes: the gem websocket-driver and Any other gem that rely on it couldn't install successfully, and the ERROR is as shown above.

1 Answers

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

Related