Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation issues with Arm Mac (M1 Chip) #1691

Closed
jasonsilberman opened this issue Dec 22, 2020 · 72 comments
Closed

Installation issues with Arm Mac (M1 Chip) #1691

jasonsilberman opened this issue Dec 22, 2020 · 72 comments

Comments

@jasonsilberman
Copy link

Hey there!

I am trying to install Ruby 2.7.2 on my new Apple Silicon Mac but am running into some issues, which I think might be related to ruby-build, but not I am not 100%.

I have setup an alias on my ~/.zshrc for Homebrew like this:

alias ibrew="arch -x86_64 /usr/local/bin/brew"

I have run the following commands in order to install rbenv:

ibrew install rbenv

rbenv init

I have updated my .zshrc file with:

eval "$(rbenv init -)"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"

And then I ran the following command:

rbenv install 2.7.2

I have also tried prefixing the rbenv command with arch -x86_64 but that did not work either.

These are the console logs that I am getting when I am trying to install Ruby:

Downloading ruby-2.7.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2
Installing ruby-2.7.2...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 11.1 using ruby-build 20201221)

Inspect or clean up the working tree at /var/folders/z1/dm8dx54j1dlgxk4zrq__x22r0000gn/T/ruby-build.20201221160748.90156.i6p4m0
Results logged to /var/folders/z1/dm8dx54j1dlgxk4zrq__x22r0000gn/T/ruby-build.20201221160748.90156.log

Last 10 log lines:
installing default nkf libraries
compiling date_strftime.c
installing default console libraries
linking shared-object objspace.bundle
compiling date_strptime.c
linking shared-object io/nonblock.bundle
linking shared-object io/console.bundle
linking shared-object nkf.bundle
linking shared-object date_core.bundle
make: *** [build-ext] Error 2

If you have any ideas for how to make this work, please let me know!

Thanks.

@hsbt hsbt transferred this issue from rbenv/rbenv Dec 22, 2020
@TheMlok
Copy link

TheMlok commented Dec 22, 2020

I have the same problem, here is full log output to help you. Also on my new MacBook Pro with M1.

installing default console libraries
readline.c:1904:37: error: use of undeclared identifier 'username_completion_function'; did you mean 'rl_username_completion_function'?
                                    rl_username_completion_function);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    rl_username_completion_function
readline.c:79:42: note: expanded from macro 'rl_username_completion_function'
# define rl_username_completion_function username_completion_function
                                         ^
/usr/local/opt/readline/include/readline/readline.h:485:14: note: 'rl_username_completion_function' declared here
extern char *rl_username_completion_function PARAMS((const char *, int));
             ^
compiling nonblock.c
installing default nkf libraries
1 error generated.
make[2]: *** [readline.o] Error 1
make[1]: *** [ext/readline/all] Error 2
make[1]: *** Waiting for unfinished jobs....

I tried different flags and absolutely no flags, aka rbenv install 2.7.2.

Thanks for excellent work, and Merry Christmas.

@hsbt
Copy link
Member

hsbt commented Dec 24, 2020

I only confirm to work native arm arch with M1 chip. I'm not sure what happened with the mix environment provided by Rosetta2.

@albertski
Copy link

I'm also running into the same issue with the M1 Chip MacBook Pro and am seeing the same undeclared identifier 'username_completion_function' error as described by @TheMlok.

@hsbt I installed via brew install rbenv command. How are you working with the native arch with M1 chip?

@hsbt
Copy link
Member

hsbt commented Dec 24, 2020

@hsbt I installed via brew install rbenv command. How are you working with the native arch with M1 chip?

Yes.

% ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]

@jlerpscher
Copy link

Same issue here with my new MBA M1. Tried with Homebrew and Basic GitHub Checkout.

@deepj
Copy link
Contributor

deepj commented Dec 25, 2020

It seems you all mix readline compiled for ARM with Ruby for x64. That will never work properly. It's not good idea to mix these platforms together. Just use separated Homebrew for ARM and for x64.

@hsbt I believe the issue is in readline. ruby-build tries to use homebrew version while building.

@Charl-e
Copy link

Charl-e commented Dec 27, 2020

Hi! Im also trying to install Ruby.

Ive been reading your post and the following answers.
I'm a bit behind on the installation, on Homebrew, as I dont know how to create a .zshrc file in my home directory export PATH="/opt/homebrew/bin:$PATH"
As seen on: https://github.com/mikelxc/Workarounds-for-ARM-mac
(Ive followed this steps before posting here)

Could you please advise on how to do this?
Not sure yet on how to do it, as Im fairly new to Mac.

Thanks!

@TheMlok
Copy link

TheMlok commented Dec 28, 2020

It seems you all mix readline compiled for ARM with Ruby for x64. That will never work properly. It's not good idea to mix these platforms together. Just use separated Homebrew for ARM and for x64.

@hsbt I believe the issue is in readline. ruby-build tries to use homebrew version while building.

Hello, please have you any rollout how to setup everything properly to the working state? I need to switch my ntb at job for a new one. I just followed guidelines. I installed homebrew with rosetta2 and then brew install rbenv.

@TheMlok
Copy link

TheMlok commented Dec 28, 2020

Hi! Im also trying to install Ruby.

Ive been reading your post and the following answers.
I'm a bit behind on the installation, on Homebrew, as I dont know how to create a .zshrc file in my home directory export PATH="/opt/homebrew/bin:$PATH"
As seen on: https://github.com/mikelxc/Workarounds-for-ARM-mac
(Ive followed this steps before posting here)

Could you please advise on how to do this?
Not sure yet on how to do it, as Im fairly new to Mac.

Thanks!

Just open terminal and vim .zshrc edit the file and save :wq.

@TheMlok
Copy link

TheMlok commented Dec 28, 2020

I only confirm to work native arm arch with M1 chip. I'm not sure what happened with the mix environment provided by Rosetta2.

Hello, please how did you install natively? Using Homebrew or compilation, please can you give some details? I will try it. Thanks.

@TheMlok
Copy link

TheMlok commented Dec 28, 2020

I have the same problem, here is full log output to help you. Also on my new MacBook Pro with M1.

installing default console libraries
readline.c:1904:37: error: use of undeclared identifier 'username_completion_function'; did you mean 'rl_username_completion_function'?
                                    rl_username_completion_function);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    rl_username_completion_function
readline.c:79:42: note: expanded from macro 'rl_username_completion_function'
# define rl_username_completion_function username_completion_function
                                         ^
/usr/local/opt/readline/include/readline/readline.h:485:14: note: 'rl_username_completion_function' declared here
extern char *rl_username_completion_function PARAMS((const char *, int));
             ^
compiling nonblock.c
installing default nkf libraries
1 error generated.
make[2]: *** [readline.o] Error 1
make[1]: *** [ext/readline/all] Error 2
make[1]: *** Waiting for unfinished jobs....

I tried different flags and absolutely no flags, aka rbenv install 2.7.2.

Thanks for excellent work, and Merry Christmas.

I have solved it. I deleted Homebrew and install it natively for ARM, installed rbenv and symlinked into /usr/local/bin. And it is working now, thanks (just a few issues in older versions, nothing dramatic.

@albertski
Copy link

albertski commented Dec 28, 2020

@TheMlok How did you install Homebrew natively for ARM? When I tried, I get "Homebrew is not (yet) supported on ARM processors".

I installed Homebrew as shown here and got the errors shown above.

@tcannonfodder
Copy link

tcannonfodder commented Dec 29, 2020

I had some success by using the latest Homebrew install script (which adds partial support for M1), then:

  1. Installing readline from source to verify that it works (brew install -s readline)
  2. installing libyaml
  3. Installing Ruby 3.0.0 (to try to reduce as many potential issues as possible)

Update: 2020-12-29: I got 2.7.2 working by:

  1. Manually installing the Xcode command line tools from apple's developer site
  2. rbenv install 2.7.2
  3. gem update to update all the installed gems (fixing native extension bugs, for example with Digest`)
  4. brew install libxml2 for nokogiri support
  5. gem install nokogiri -- --use-system-libraries

@albertski
Copy link

With the latest version of Homebrew I was able to install rbenv without any issues. (Also had to install openssl)

@aguynamedben
Copy link

aguynamedben commented Dec 30, 2020

tl;dr make sure you're using rbenv to install a recent release of Ruby, i.e. Ruby 2.7.2 instead of Ruby 2.7.1

I did this all today on a new 13" M1 MacBook Pro

  • Install homebrew 2.7.1 (not Ruby 2.7.1!) using the normal questionable curl method. It installs everything to /opt/homebrew as described here. The purpose of installing arm64 homebrew there seems to be to prevent confusion for some users that may also have x64 homebrew installed and running under Rosetta 2.
  • Make sure you add the new Homebrew binary path to your bash/zsh config
    # in ~/.zshrc, ~/.bashrc, etc.
    # Homebrew on the M1, where things install to /opt/homebrew
    export PATH=/opt/homebrew/bin:$PATH
    
  • Heed @tcannonfodder's advice to manually install Xcode command line tools from Apple's site (not sure if this helped)
  • brew install rbenv, which worked, then followed standard instructions to update my .zshrc (no special tweaks to .zshrc)

I then noticed that rbenv install 2.7.1 was failing after waiting a bit at the ruby-build readline step:

$ rbenv install 2.7.1
Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 11.1 using ruby-build 20201225)

Inspect or clean up the working tree at /var/folders/61/3vc6t96j6qx7q9cnhl3zdgbh0000gn/T/ruby-build.20201229203606.72951.pPOy0H
Results logged to /var/folders/61/3vc6t96j6qx7q9cnhl3zdgbh0000gn/T/ruby-build.20201229203606.72951.log

Last 10 log lines:
compiling psych_to_ruby.c
compiling new.c
compiling psych_yaml_tree.c
compiling ../.././ext/psych/yaml/reader.c
compiling ../.././ext/psych/yaml/scanner.c
compiling ../.././ext/psych/yaml/writer.c
linking shared-object -test-/string.bundle
linking shared-object zlib.bundle
linking shared-object psych.bundle
make: *** [build-ext] Error 2

But following what worked for @tcannonfodder, rbenv install 2.7.2 magically worked....

$ rbenv install 2.7.2
Downloading ruby-2.7.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2
Installing ruby-2.7.2...
ruby-build: using readline from homebrew
Installed ruby-2.7.2 to /Users/ben/.rbenv/versions/2.7.2

$ rbenv versions
* system (set by /Users/ben/.rbenv/version)
  2.7.2

$ rbenv global 2.7.2

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]

From there, I updated the required Ruby version in my project's Gemfile, ran bundle, and... everything did not work. I got some compilation errors from some Ruby Gems that have native dependencies—ffi, sassc, pg, and puma—but all I had to do was upgrade them to their latest version and everything worked.

$ brew install postgresql
$ bundle update ffi sassc pg puma

For what it's worth, the nvm install script worked fine, as well as nvm install stable, which installed Node v15.5.0 after 15 minutes of fun g++/c++/cc output as it compiled Node from source.

Entertainingly, as Node compiled from source and there were 4x clang instances showing in Activity Monitor at all times for 15 minutes, my computer seemed bored and everything was ⚡ fast! Yay M1.

@dtgay
Copy link

dtgay commented Dec 30, 2020

⚠️ Note that this comment refers to installing homebrew, rbenv, and ruby all natively on an M1 Mac. I did not use the ibrew setup, any arch-related commands, or or any Rosetta. Happy to open another issue if this belongs elsewhere, but I figured this would be where people looking for solutions to this issue will end up, like I did.

I can confirm that while Ruby 2.7.1 fails to install, both 2.7.2 and 3.0.0 succeed without a problem. This echos @aguynamedben's findings immediately above.

I'm curious as to why this happens, but am happy to know that I have access to a 2.7.x build for the time being. Here's the output of attempting to install each version, for the curious:

❯ which brew
/opt/homebrew/bin/brew
❯ rbenv install 3.0.0
Downloading openssl-1.1.1i.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
Installing openssl-1.1.1i...
Installed openssl-1.1.1i to /Users/david/.rbenv/versions/3.0.0

Downloading ruby-3.0.0.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Installing ruby-3.0.0...
ruby-build: using readline from homebrew
Installed ruby-3.0.0 to /Users/david/.rbenv/versions/3.0.0

❯ rbenv install 2.7.1
Downloading openssl-1.1.1i.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
Installing openssl-1.1.1i...
Installed openssl-1.1.1i to /Users/david/.rbenv/versions/2.7.1

Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 11.1 using ruby-build 20201225)

Inspect or clean up the working tree at /var/folders/3v/6w3dkjm53t93pl421z69hxy40000gn/T/ruby-build.20201229164713.97660.oI7UpS
Results logged to /var/folders/3v/6w3dkjm53t93pl421z69hxy40000gn/T/ruby-build.20201229164713.97660.log

Last 10 log lines:
compiling psych_parser.c
compiling psych_to_ruby.c
compiling psych_yaml_tree.c
compiling ../.././ext/psych/yaml/reader.c
compiling ../.././ext/psych/yaml/scanner.c
compiling ../.././ext/psych/yaml/writer.c
linking shared-object stringio.bundle
linking shared-object zlib.bundle
linking shared-object psych.bundle
make: *** [build-ext] Error 2

❯ rbenv install 2.7.2
Downloading openssl-1.1.1i.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
Installing openssl-1.1.1i...
Installed openssl-1.1.1i to /Users/david/.rbenv/versions/2.7.2

Downloading ruby-2.7.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2
Installing ruby-2.7.2...
ruby-build: using readline from homebrew
Installed ruby-2.7.2 to /Users/david/.rbenv/versions/2.7.2

@tcannonfodder
Copy link

Update: I was running into issues with Ruby 2.7.2, where the Digest libraries were not being compiled. I have been trying to reinstall, but running into errors. Installation log is here: https://gist.github.com/tcannonfodder/677cece3886340d41da78bb75e4003c6

@amaurybernard
Copy link

amaurybernard commented Dec 31, 2020

Hi! I think i find a way.

I just install ruby 2.7.1 using

RUBY_CFLAGS="-w" rbenv install 2.7.1

Watching as the logs i saw the problem (for me) was a useless warning so i just disable -Wall with -w

losure.c:264:14: error: implicit declaration of function 'ffi_prep_closure' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    result = ffi_prep_closure(pcl, cif, callback, (void *)self);
             ^
1 error generated.

I hope it works for you 😃

@Charl-e
Copy link

Charl-e commented Dec 31, 2020

3\. gem update

@tcannonfodder Im following your steps and while executing gem update I get the following message:

Updating installed gems
Updating CFPropertyList
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

May I ask you, did you stumbled upon the same?
How do I upgrade my permissions?

@Charl-e
Copy link

Charl-e commented Jan 2, 2021

If I directly try to execute rbenv install 2.7.2 in the Terminal I get the message: "command not found: rbenv"

So I thought I need to designate the right path, but I presume Im executing the wrong command to install Rbenv:
sudo rm -rf $HOME/.rbenv /usr/local/rbenv /opt/rbenv /usr/local/opt/rbenv
then:
brew uninstall --force rbenv ruby-build
and finally:
brew install rbenv
rbenv install 2.7.2

But if I want to check the version, I dont see is the right one:

ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.arm64e-darwin20]

@kirichkov
Copy link

I just want to share my experience and to thank @amaurybernard for pointing me in the right direction:

  1. I installed brew using the "official" method
  2. I installed rbenv and ruby-build without any options (i.e. no prefixing with arch -arm64 or arch -x86_64
  3. Used RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.5.3 (yes you read that right 2.5.3 compiled without any issues!)

If the ffi gem gives you any more troubles first install the latest version with gem install ffi, and then update the bundled one (if using budler at all)

While @amaurybernard disabled all warnings, I disabled just the one causing the compile issue. As it turns out this compilation issue has already been discussed for ffi

@jtomaszewski
Copy link

Yeah, by prefixing any rbenv install ... or asdf install ruby ... with RUBY_CFLAGS="-Wno-error=implicit-function-declaration", I managed to install ruby 2.4.10, 2.5.8, 2.6.6 locally in native mode (without rosetta). Thanks @kirichkov and @amaurybernard .

@ChrisZou
Copy link

ChrisZou commented Jan 23, 2021

I also ran into this error when installing ruby 2.7.2 using RVM on M1. Fixed by installing another homebrew (arm version)

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

and then install readline using arm version homebrew. Then the error got fixed.

@SalvatoreT
Copy link

@santostiago's solution on #1699 (comment) worked for me!

export optflags="-Wno-error=implicit-function-declaration"; export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"; export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"; export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig" | rbenv install 2.7.2

@ferbass
Copy link

ferbass commented Feb 3, 2021

I got into he same issue and here is my sollution

First make sure you have openssl and readline

brew install readline
brew install openssl

Set the path to openssl and the environment variables required for ruby compilation into your ~/.zshrc

// Homebrew
export PATH=/opt/homebrew/bin:$PATH
export PATH="/opt/homebrew/sbin:$PATH"

// rbenv
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"

// openssl
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"

Now you should be able to install ruby in your M1 machine

@next-luisalbertoleon
Copy link

I have some problems with ruby like I read in this issue, I followed this "guide":
https://www.driftingruby.com/episodes/a-rubyist-s-apple-m1-review

and I have ruby working now:

 ~ $% \curl -sSL https://get.rvm.io | bash -s stable
 ~ $% source $HOME/.rvm/scripts/rvm
 ~ $% rvm install 2.7.2
ruby-2.7.2 - #removing src/ruby-2.7.2 - please wait
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/11.0/arm64/ruby-2.7.2.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system - please wait
Installing required packages: automake, coreutils, libyaml, zlib - please wait
Certificates bundle '/opt/homebrew/etc/[email protected]/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/devops/.rvm/rubies/ruby-2.7.2, this may take a while depending on your cpu(s)...
ruby-2.7.2 - #downloading ruby-2.7.2, this may take a while depending on your connection...
ruby-2.7.2 - #extracting ruby-2.7.2 to /Users/devops/.rvm/src/ruby-2.7.2 - please wait
ruby-2.7.2 - #configuring - please wait
	ruby-2.7.2 - #post-configuration - please wait
ruby-2.7.2 - #compiling - please wait
ruby-2.7.2 - #installing - please wait
ruby-2.7.2 - #making binaries executable - please wait
Installed rubygems 3.1.4 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.7.2 - #gemset created /Users/devops/.rvm/gems/ruby-2.7.2@global
ruby-2.7.2 - #importing gemset /Users/devops/.rvm/gemsets/global.gems - please wait
ruby-2.7.2 - #generating global wrappers - please wait
ruby-2.7.2 - #gemset created /Users/devops/.rvm/gems/ruby-2.7.2
ruby-2.7.2 - #importing gemsetfile /Users/devops/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.7.2 - #generating default wrappers - please wait
ruby-2.7.2 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.7.2 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

 ~ $% ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]

hope it helps anyone :)

@redferret
Copy link

I got into he same issue and here is my sollution

First make sure you have openssl and readline

brew install readline
brew install openssl

Set the path to openssl and the environment variables required for ruby compilation into your ~/.zshrc

// Homebrew
export PATH=/opt/homebrew/bin:$PATH
export PATH="/opt/homebrew/sbin:$PATH"

// rbenv
export RBENV_ROOT=/opt/homebrew/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"

// openssl
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"

Now you should be able to install ruby in your M1 machine without any problem.

I tried this solution and it still doesn't work
This is the output the console gives for me

Downloading ruby-3.0.0.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Installing ruby-3.0.0...
ruby-build: using readline from homebrew
/opt/homebrew/bin/ruby-build: line 1121: 69588 Killed: 9               "$RUBY_BIN" -e '
    manager = ARGV[0]
    packages = {
      "apt-get" => Hash.new {|h,k| "lib#{k}-dev" }.update(
        "openssl" => "libssl-dev",
        "zlib" => "zlib1g-dev"
      ),
      "yum" => Hash.new {|h,k| "#{k}-devel" }.update(
        "yaml" => "libyaml-devel"
      )
    }

    failed = %w[openssl readline zlib yaml].reject do |lib|
      begin
        require lib
      rescue LoadError
        $stderr.puts "The Ruby #{lib} extension was not compiled."
      end
    end

    if failed.size > 0
      $stderr.puts "ERROR: Ruby install aborted due to missing extensions"
      $stderr.print "Try running `%s install -y %s` to fetch missing dependencies.\n\n" % [
        manager,
        failed.map { |lib| packages.fetch(manager)[lib] }.join(" ")
      ] unless manager.empty?
      $stderr.puts "Configure options used:"
      require "rbconfig"; require "shellwords"
      RbConfig::CONFIG.fetch("configure_args").shellsplit.each { |arg| $stderr.puts "  #{arg}" }
      exit 1
    end
  ' "$(basename "$(type -p yum apt-get | head -1)")" 1>&4 2>&1

BUILD FAILED (macOS 11.2 using ruby-build 20210119)

Inspect or clean up the working tree at /var/folders/rn/c7nmr3x12gg5r8qwsr4ty8hh0000gn/T/ruby-build.20210210161642.31102.pyKQOf
Results logged to /var/folders/rn/c7nmr3x12gg5r8qwsr4ty8hh0000gn/T/ruby-build.20210210161642.31102.log

Last 10 log lines:
installing bundled gems:            /opt/homebrew/opt/rbenv/versions/3.0.0/lib/ruby/gems/3.0.0
                                    minitest 5.14.2
                                    power_assert 1.2.0
                                    rake 13.0.3
                                    test-unit 3.3.7
                                    rexml 3.2.4
                                    rss 0.2.9
                                    rbs 1.0.0
                                    typeprof 0.11.0
installing bundled gem cache:       /opt/homebrew/opt/rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/cache

@ehaselwanter
Copy link

  • so I got the error after "upgrading" to brew 3.0.1 which should have resolved the issue.
  • uninstall and re-install rbenv and ruby-build did not help

=> completely uninstall homebrew and starting fresh resolved it for me.

@nimeshatpair
Copy link

Hi! I think i find a way.

I just install ruby 2.7.1 using

RUBY_CFLAGS="-w" rbenv install 2.7.1

Watching as the logs i saw the problem (for me) was a useless warning so i just disable -Wall with -w

losure.c:264:14: error: implicit declaration of function 'ffi_prep_closure' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    result = ffi_prep_closure(pcl, cif, callback, (void *)self);
             ^
1 error generated.

I hope it works for you 😃

Thanks! This easy fix worked for me 👍

@juliocabrera820
Copy link

rvm install 2.5 --with-out-ext=fiddle can do the job also

It works 👌🏼

@johnpitchko
Copy link

@bradical I'm using zsh and these are what I did

  • brew install libffi
  • Add these line to the bottom of ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
  • source ~/.zshrc

Adding libffi worked for me w/ installing ruby-2.6.6.

Curiously, I was able to install ruby-3.0.2 first and had no issue. So does 2.6.6 (and others) have some build dependency on libffi?

@nicolasconnault
Copy link

I went through many of the above solutions and ended up making a mess of my .zshrc file, and nothing worked.

At the end I deleted everything related to this (LD_FLAGS, CPPFLAGS, PKG_CONFIG_FLAGS etc.) from my .zshrc file and simply ran this command:

RUBY_CFLAGS="-Wno-error=implicit-function-declaration" arch -x86_64 rbenv install 3.0.2

BINGO!

@julesce
Copy link

julesce commented Oct 30, 2021

@bradical I'm using zsh and these are what I did

  • brew install libffi
  • Add these line to the bottom of ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
  • source ~/.zshrc

I was struggling to install Ruby 2.5.9 on Monterey (12.0.1) and was getting the following error:

BUILD FAILED (macOS 12.0.1 using ruby-build 20211019)

But manhcuongdtbk's suggestion above got it working, so thank you! 🍻

@xantrac
Copy link

xantrac commented Nov 4, 2021

Hello, jumping on the wagon this is what I'm getting installing ruby 2.7.3 on OSX Monterey with M1 Pro

-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.3.tar.bz2
Installing ruby-2.7.3...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 12.0 using ruby-build 20211019)

Inspect or clean up the working tree at /var/folders/zl/q4dvs0h565g0fht06zp7h8yr0000gp/T/ruby-build.20211103213158.97009.SPN4C7
Results logged to /var/folders/zl/q4dvs0h565g0fht06zp7h8yr0000gp/T/ruby-build.20211103213158.97009.log

Last 10 log lines:
checking whether clang accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking for clang option to accept ISO C99... none needed
checking for clang++... clang++
checking whether we are using the GNU C++ compiler... yes
checking whether clang++ accepts -g... yes
checking how to run the C preprocessor... clang -E
checking if minimum required OS X version is supported... no
configure: error: Unsupported OS X version is required
make: *** No targets specified and no makefile found.  Stop.

wasn't able to find any similar case

@alvincrespo
Copy link

  • brew install libffi
  • Add these line to the bottom of ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
  • source ~/.zshrc

@manhcuongdtbk solution worked perfectly for me! Thank you!

@wanderlust-create
Copy link

I was having the same problem. M1 chip + Monterey.

This is what worked for me:

  1. Uninstalled homebrew
  2. Unchecked the "Open using Rosetta" option in Terminal Info (I had to check this to download homebrew).
  3. Reinstalled homebrew
  4. Had to install rbenv again
  5. rbenv install 2.7.4

@keating
Copy link

keating commented Nov 12, 2021

rvm install 2.5 --with-out-ext=fiddle can do the job also

It works 👌🏼

works like a charm!

@goelinsights
Copy link

goelinsights commented Nov 27, 2021

Thanks to all for the comments. Been tripped up on this for a couple hours until I stumbled on this thread. Here's what worked for me on a new M1 Max after migration assistant from a 2017 MBP 16"

  1. I used which brew to verify that homebrew was set for arm 64
  2. I added homebrew folder to the PATH in .zshrc and also the rebenv init
    export PATH="/opt/homebrew/bin:$PATH"
    eval "$(rbenv init - zsh)"
  3. uninstalled and reinstalled rbenv in brew
  4. ran rbenv init

Rbenv on installing a new version pulled in openssl into its build, which solved the error I had encountered where it said I didn't have openSSL:
#1277
#rubygems/rubygems#4192

@bradical
Copy link

Thanks @goelinsights can you confirm which version of Ruby you were installing? I was still having problems with Ruby 2.2.2 up until very recently so I will give your directions a shot.

@rogerluan
Copy link

Adding to this already really long thread/issue to contribute with my 2cents 😄
Turns out that my homebrew installation was effed up on my M1 machine, and that's the reason I wasn't able to install Ruby anymore. I had both versions of homebrew installed (arm64 and x86) in different places, but the x86 was the default one (the one picked up by which brew). So I thought modifying my PATH would fix it, but it didn't, for unknown reason. This is the error I used to see when running brew install on M1 Terminal:

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
  https://docs.brew.sh/Installation

The solution was as follows:

  1. Take note of all the programs you have installed using brew list. Save this list for future reference.
  2. Used this official uninstallation script to get rid of both Homebrews I had by running it twice, by passing --path=/usr/local/Homebrew and --path=/opt/homebrew respectively (which's where the 2 versions of my Homebrew were living). I know this sucks a lot because you lose all your packages, that's why we saved them in the previous step.
  3. The previous step failed to me (the uninstallation threw errors). There were left over files which I HAD to delete manually (I tried proceeding without doing that and failed). So: sudo rm -rf /usr/local/Homebrew and sudo rm -rf /opt/homebrew
  4. Install it again 😇 Just run the script found at the homepage https://brew.sh this will install your new brew at /opt/homebrew if you're on M1, by default. Which's where it should live.
  5. Once the installation finishes, it will suggest you to add brew to your PATH. Please do that. This is critical. It will suggest this:
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/your-username/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

Run those 2 commands.

  1. Now which brew should point to /opt/homebrew/bin/brew 🎉 and you'll be able to run brew install … native on M1 without switching to Rosetta Terminal, or append a arch -x86_64 prefix. Great!
  2. Now you'll need to install everything again 😅 That is: brew install openssl libffi zlib rbenv readline ruby-build
  3. rbenv install 2.7.5 (or whatever version you were trying to install before).

Done! 🎉

image

What Next?

Install everything else you think you might need to reinstall (that you saved on step 1). 🙈

Hope this helps!

@tamphh
Copy link

tamphh commented Dec 3, 2021

My colleague helped me solving this problem with script below:

#!/usr/bin/env bash

set -e

# ruby-install --latest

OPENSSL_VERSION=1.1
OPENSSL_DIR=/usr/local/opt/openssl@${OPENSSL_VERSION}

function install-ruby-on-mac() {
    PKG_CONFIG_PATH=${OPENSSL_DIR}/lib/pkgconfig \
    ruby-install $(ruby-install-options $1) \
        ruby $1 \
        -- \
        --with-openssl-dir=${OPENSSL_DIR} \
        --with-opt-dir=$(brew --prefix readline) \
        --without-tcl --without-tk
}

install-ruby-on-mac 2.5.8
install-ruby-on-mac 2.6.8
install-ruby-on-mac 2.7.4

Hope it could help someone.

@iltempo
Copy link

iltempo commented Dec 15, 2021

Actually, a simple arch -arm64 rbenv install 3.0.3 did the job for me. No need to bend library paths.

@andreluizsgf
Copy link

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.6 worked great for me.

@bradical
Copy link

Thanks @andreluizsgf. And did you have to force -x86 in order to install 2.6.6?

@robbyrussell
Copy link

Hi! I think i find a way.

I just install ruby 2.7.1 using

RUBY_CFLAGS="-w" rbenv install 2.7.1

This worked for me to install 2.6.7 on my new Apple M1 MBP

@bradical
Copy link

bradical commented Dec 22, 2021

And @robbyrussell are you using an arm or x86 version of homebrew to install rbenv?

@iltempo
Copy link

iltempo commented Dec 22, 2021

Actually, a simple arch -arm64 rbenv install 3.0.3 did the job for me. No need to bend library paths.

I figured I'd run into problems compiling Ruby or third-party libraries since I did not use an arm64 shell.
You can check the architecture used by your shell with uname -m.

@rbenv rbenv locked and limited conversation to collaborators Dec 26, 2021
@hsbt hsbt converted this issue into discussion #1853 Dec 26, 2021
@hsbt hsbt unpinned this issue Dec 26, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests