Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error installing ruby 2.6.7 on mac os - how to resolve?

Tags:

I get the following error when trying to upgrade Ruby to 2.6.7:

$ rbenv install 2.6.7

...


implicit declaration of function 'rb_native_mutex_destroy' is invalid in C99
vm.c:2489:34: warning: expression does not compute the number of elements in this array; element type is 'const int', not 'VALUE' (aka 'unsigned long') [-Wsizeof-array-div]
                             sizeof(ec->machine.regs) / sizeof(VALUE));
                                    ~~~~~~~~~~~~~~~~  ^
vm.c:2489:34: note: place parentheses around the 'sizeof(VALUE)' expression to silence this warning

Is there a fix?

like image 908
Gavin Miller Avatar asked Apr 09 '21 14:04

Gavin Miller


People also ask

How do I install the latest version of Ruby on Mac?

Note that MacOS users seldom download Ruby to build from source. Instead, Mac users install the latest Ruby with Homebrew or get the latest Ruby version with the installation utilities that accompany a version manager such as asdf, chruby, rbenv, or rvm.

Do I need Xcode to install Ruby?

You need to install Apple's Xcode Command Line Tools to get the Unix tools needed to install Ruby and develop applications. Apple's Xcode Command Line Tools provide a C language compiler. You'll need it to install Ruby.

Can Mac run Ruby?

If you're using Ruby on a Mac, it is set up by default, but you can't modify or upgrade it. Most developers don't use the pre-installed version of Ruby on their Macs. Instead, they configure several systems to help them manage Ruby installation (and other programs), and manage different versions of Ruby.


2 Answers

Additionally to following Gavin's answer, I had to reinstall readline. brew reinstall readline

like image 24
Marwa Abdallah Avatar answered Sep 23 '22 11:09

Marwa Abdallah


Yes, this is a known issue upstream: https://bugs.ruby-lang.org/issues/17777
ruby-build is also tracking this issue: https://github.com/rbenv/ruby-build/issues/1489

The work around is to run the following code, and install ruby 2.6.7 again:

$ export warnflags=-Wno-error=implicit-function-declaration
$ rbenv install 2.6.7

-or-

$ CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.7

Looks like this can also impact gem installation with native extensions (mysql2 is one of those):

gem install <GEMNAME> -- --with-cflags="-Wno-error=implicit-function-declaration"
like image 191
Gavin Miller Avatar answered Sep 21 '22 11:09

Gavin Miller