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.
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 only confirm to work native arm arch with M1 chip. I'm not sure what happened with the mix environment provided by Rosetta2.
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 I installed via
brew install rbenvcommand. 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]
Same issue here with my new MBA M1. Tried with Homebrew and Basic GitHub Checkout.
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.
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!
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-buildtries 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.
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.
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.
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.
@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.
I had some success by using the latest Homebrew install script (which adds partial support for M1), then:
readline from source to verify that it works (brew install -s readline)libyamlUpdate: 2020-12-29: I got 2.7.2 working by:
rbenv install 2.7.2gem update to update all the installed gems (fixing native extension bugs, for example with Digest`)brew install libxml2 for nokogiri supportgem install nokogiri -- --use-system-librariesWith the latest version of Homebrew I was able to install rbenv without any issues. (Also had to install openssl)
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
# in ~/.zshrc, ~/.bashrc, etc.
# Homebrew on the M1, where things install to /opt/homebrew
export PATH=/opt/homebrew/bin:$PATH
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.
⚠️ 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
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
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 😃
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?
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]
I just want to share my experience and to thank @amaurybernard for pointing me in the right direction:
arch -arm64 or arch -x86_64RUBY_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
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 .
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.
@santostiago's solution on https://github.com/rbenv/ruby-build/issues/1699#issuecomment-762122911 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
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
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 :)
I got into he same issue and here is my sollution
First make sure you have
opensslandreadlinebrew install readline brew install opensslSet 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
=> completely uninstall homebrew and starting fresh resolved it for me.
This is what worked for me for installing ruby 2.6.6 on M1.
brew install openssl
Add to ~/.zshrc
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
Run
RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.6
For those who also want to work with the older architecture for now and not use M1 chip please look at the workaround I posted on stack overflow. This should work for most people.
This is what worked for me for installing ruby 2.6.6 on M1.
Thanks @hackedunit, your instructions worked for me too. My config: Mini M1, Big Sur 11.2.1, a clean, first-time install of Homebrew 3.0.2, rbenv 1.1.2 and Ruby 2.7.2 already installed without issues, as a first install after installing brew and rbenv. Then update to Big Sur 11.2.2 has been applied. Attempts to install Ruby 2.6.6 were failing with errors:
compiling fiddle.c
closure.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.
After installing openssl and adding it to PATH I ran your
RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.6
and it worked correctly.
I saw this when running rbenv install 2.7.2 on Mac M1 (Big Sur 11.2.2).
Not using Rosetta at the moment, and I solved the issue by uninstalling readline (brew uninstall readline), and then installing it fresh again (brew install readline). Readline binary coming from brew already targets arm architecture:
➜ brew install readline
==> Downloading https://homebrew.bintray.com/bottles/readline-8.1.arm64_big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/940e7c2b80ef7f59b26726a5669a31fcb8ba7cbbb17eb1f2ca589dafa6e68e5e?response-co
######################################################################## 100.0%
==> Pouring readline-8.1.arm64_big_sur.bottle.tar.gz
rvm install 2.5 --with-out-ext=fiddle
can do the job also
Guys, after a lot of time, i managed how to install it properly on m1.
With RUBY_CFLAGS="-w" it will install a bad performatic version of ruby for some reason.
With RUBY_CFLAGS="-Wno-error=implicit-function-declaration" same issue.
The workround that i did to install properly is:
sudo xcodebuild -license agree
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"
export PATH="/opt/homebrew/opt/sqlite/bin:$PATH"
alias abrew='/opt/homebrew/bin/brew'
alias ibrew='arch -x86_64 /usr/local/bin/brew'
exec $SHELL
brew install openssl libffi zlib rbenv readline ruby-build
exec $SHELL
RUBY_CONFIGURE_OPTS=--with-readline-dir="$(abrew --prefix readline)"
rbenv install 2.7.1
LDFLAGS="-L/opt/homebrew/opt/libffi/lib" CPPFLAGS="-I/opt/homebrew/opt/libffi/include" RUBY_CONFIGURE_OPTS=--with-readline-dir="$(abrew --prefix readline)"
rbenv install 2.7.1
-
The rspec time for 1 big test, from 3 minutes, droped to 39 SECONDS!
I saw this when running
rbenv install 2.7.2on Mac M1 (Big Sur 11.2.2).
Not using Rosetta at the moment, and I solved the issue by uninstalling readline (brew uninstall readline), and then installing it fresh again (brew install readline). Readline binary coming from brew already targets arm architecture:➜ brew install readline ==> Downloading https://homebrew.bintray.com/bottles/readline-8.1.arm64_big_sur.bottle.tar.gz ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/940e7c2b80ef7f59b26726a5669a31fcb8ba7cbbb17eb1f2ca589dafa6e68e5e?response-co ######################################################################## 100.0% ==> Pouring readline-8.1.arm64_big_sur.bottle.tar.gz
It works for me !
Running rbenv install 3.0.0 on Mac M1 (Big Sur 11.2.3) after by uninstalling & installing readline
Has anyone managed to overcome this type of issue when installing older versions of Ruby on Arm chips? Feels like it's a problem with the ruby build no recognizing the architecture properly https://github.com/rbenv/ruby-build/issues/1700#issuecomment-811381254 https://github.com/rbenv/ruby-build/issues/1742
I tried all of the above fixes but I still get the readline error when trying to 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
BUILD FAILED (macOS 11.2.3 using ruby-build 20210405)
Inspect or clean up the working tree at /var/folders/v4/j08lwwzn59bf46vhy69fr5l40000gn/T/ruby-build.20210410132943.75093.EDb6tw
Results logged to /var/folders/v4/j08lwwzn59bf46vhy69fr5l40000gn/T/ruby-build.20210410132943.75093.log
And this is part of the tail for the log file.
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
^
/opt/homebrew/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));
^
1 error generated.
make[2]: *** [readline.o] Error 1
make[1]: *** [ext/readline/all] Error 2
make[1]: *** Waiting for unfinished jobs....
compiling console.c
installing default date_core libraries
linking shared-object objspace.bundle
installing default console libraries
linking shared-object io/console.bundle
linking shared-object nkf.bundle
linking shared-object date_core.bundle
These notes _might_ be useful. I was having similar problems, but with asdf.
After trying to update to 2.7.3 using several fixes for several weeks, I made some changes in my .zshrc file, and was able to upgrade from 2.6.6 to 2.7.3 successfully.
After running rbenv install 2.7.3 on my Apple M1 chip computer (MacOS Big Sur), my log stated this error:
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
^
/opt/homebrew/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 date_strftime.c
1 error generated.
I could not get around it. Since I am not that much of dev ops person, I looked at my .zshrc file for mistakes and how I was handling paths. After making some adjustments and creating an alias for brew, my current .zshrc looks like so:
# Alias
alias brew="arch -x86_64 /usr/local/bin/brew"
# Environment
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
export PATH="/usr/local/opt/node@14/bin:$PATH"
export PATH="/usr/local/opt/postgresql@12/bin:$PATH"
export PATH="/opt/homebrew/opt/sqlite/bin:$PATH"
eval "$(rbenv init -)"
export PKG_CONFIG_PATH="${PKGCFGDIR} $PKG_CONFIG_PATH"
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH="/usr/local/opt/postgresql@12/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig:$PKG_CONFIG_PATH"
export CPPFLAGS="${CPPFLAGS} $CPPFLAGS"
export CPPFLAGS="-I/usr/local/opt/postgresql@12/include:$CPPFLAGS"
export CPPFLAGS="-I/usr/local/opt/sqlite/include:$CPPFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/zlib/include:$CPPFLAGS"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include:$CPPFLAGS"
export LDFLAGS="${LDFLAGS} $LDFLAGS"
export LDFLAGS="-L/usr/local/opt/postgresql@12/lib:$LDFLAGS"
export LDFLAGS="-L/usr/local/opt/sqlite/lib:$LDFLAGS"
export LDFLAGS="-L/opt/homebrew/opt/zlib/lib:$LDFLAGS"
export LDFLAGS="-L/usr/local/opt/[email protected]/lib:$LDFLAGS"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected]) --with-readline-dir=$(brew --prefix readline)"
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
export PATH="/usr/local/sbin:$PATH"
export PATH="/usr/local/opt/sqlite/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
There might be other things I could clean up, as I can chain things, but for what I need. I am now running 2.7.3 on my Apple M1 chip computer successfully. I hope this helps someone else.
@MsDaciaCare, are you sure that mixing archs is a way to go? You use Intel version of Homebrew (fist alias in your file), but then define paths from the ARM version (/opt/homebrew). Can you specify what architecture is your Ruby 2.7.3 installation? And what is your Homebrew version?
Most helpful comment
Yeah, by prefixing any
rbenv install ...orasdf install ruby ...withRUBY_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 .