Skip to content
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

Error: "rm: illegal option -- a" installing ruby 2.2.2 on MacOS v11.2.3 Apple M1 Silicon #1742

Closed
bradical opened this issue Apr 1, 2021 · 9 comments

Comments

@bradical
Copy link

bradical commented Apr 1, 2021

Steps:

It seems to fail at the very end with a strange error about an illegal option for rm:

config.status: creating -darwin20-fake.rb
rm: illegal option -- a
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
config.status: error: could not create -darwin20-fake.rb
make: *** [-darwin20-fake.rb] Error 64

I thought this might be related to #1700 or #1691 but it seems a bit different than both so I filed separately.

ruby-build.20210331213055.45512.log

@bradical bradical changed the title Error: "rm: illegal option -- a" installing ruby 2.2.2 on MacOS v11.2.3 on Apple M1 Silicon Error: "rm: illegal option -- a" installing ruby 2.2.2 on MacOS v11.2.3 Apple M1 Silicon Apr 1, 2021
@bradical
Copy link
Author

bradical commented Apr 1, 2021

Can confirm this happening when building ruby from source using:

./configure --prefix /Users/bradley/Downloads/temp
make
make install

which tells me this is not a ruby-build problem per se. Still, I have no other leads on this so if anyone has any ideas, that would be much appreciated. Feels like a problem with the arch somewhere in this make or make install that is resulting in an invalid command to rm perhaps due ot the name of the file -darwin20-fake.rb. The leading - maybe?

@hsbt
Copy link
Member

hsbt commented Apr 1, 2021

At first, Ruby 2.2 is not supported M1 macOS and it's EOL today. I (also includes Ruby core team) have no plan to support it.

@hsbt hsbt closed this as completed Apr 1, 2021
@bradical
Copy link
Author

bradical commented Apr 1, 2021

I understand and I'd like to upgrade as soon as I can but I need to get this running first. Is there anything obvious in that make file in the final linking step that I could tweak to get this to work? This seems like a bad substitution or something as it ended up with a file called -darwin-fake.rb. Could I override or specify the arch in some way?

@kule
Copy link

kule commented May 9, 2021

For anyone else interested this is how I got 2.2.10 to install on m1 mac:

Firstly to get openssl1.0 installed you need a patched version that accounts for the arch (thanks @felixbuenemann):

https://gist.github.com/felixbuenemann/5f4dcb30ebb3b86e1302e2ec305bac89#gistcomment-3567911

Try to install ruby 2.2.10 as per normal in rbenv:

CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" rbenv install 2.2.10

After a while it'll fail as noted by @bradical with:

config.status: creating -darwin20-fake.rb
rm: illegal option -- a
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
config.status: error: could not create -darwin20-fake.rb
make: *** [-darwin20-fake.rb] Error 64

fyi @brandical I also wondered if the -darwin20-fake.rb was an error as usually it'd be something like x86_64-darwin20-fake.rb but I noticed this is just -darwin20-fake.rb with ruby 2.4 and works fine.

Anyways, take a note the debug log directory and go to ruby directory in that path e.g.

$> cd /private/var/folders/yc/_clcptvx4nq0vw_h6frtk0j00000gn/T/ruby-build.20210509110656.28571.vlttTy/ruby-2.2.10

I traced the error in config.status to this line 1097 (fyi $ac_file is -darwin20-fake.rb):

*) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;

It's obviously running the command as if -darwin20-fake.rb are args to the rm command rather than a filename and failing (e.g. simplified it's trying to run rm -rfdarwin20-fake.rb and bailing when it gets to the a in darwin as it's not a valid argument for rm).

There's most probably a better way to do this but for now it worked to just remove the rm -f part of the command:

*) mv "$ac_tmp/out" "$ac_file";;

$> make && make install

voila working 2.2.10 ruby on m1 macs with rbenv.

@bradical
Copy link
Author

bradical commented May 10, 2021

Thanks for posting this @kule! Looking forward to trying this out and will report back here.

UPDATE: I was able to workaround the issue mentioned below by adding a export optflags="-Wno-error=implicit-function-declaration" after which I was able to install gems in my newly installed Ruby 2.2.2 version. Thanks again @kule for debugging the build

UPDATE: Unfortunately, this didn't work for me but I got Ruby installed successfully as you did using the steps above. I'm now running into something that may be unrelated and—based on some Stack Overflow research—might be related to OpenSSL or zlib? Any time I try to install gems I get the following:

$ gem install bundler
ERROR:  Loading command: install (LoadError)
	cannot load such file -- zlib
ERROR:  While executing gem ... (NoMethodError)

Steps to install:

  • brew install rbenv/tap/[email protected]
  • CONFIGURE_OPTS=--with-openssl-dir=/opt/homebrew/opt/[email protected] rbenv install 2.2.2
  • Navigate to tmp directory for rbenv's install
  • Modify config.status as per above
  • make && make install
    Installation succeeds but gem commands in this ruby version fail.

The RUBYGEMS PLATFORMS below looks suspect: -darwin-20:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5
  - RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [-darwin20]
  - INSTALLATION DIRECTORY: /Users/bradleywagner/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0
  - RUBY EXECUTABLE: /Users/bradleywagner/.rbenv/versions/2.2.2/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/bradleywagner/.rbenv/versions/2.2.2/bin
  - SPEC CACHE DIRECTORY: /Users/bradleywagner/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/bradleywagner/.rbenv/versions/2.2.2/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - -darwin-20
  - GEM PATHS:
     - /Users/bradleywagner/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0
     - /Users/bradleywagner/.gem/ruby/2.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :benchmark => false
     - "gem" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/bradleywagner/.rbenv/versions/2.2.2/bin
     - /opt/homebrew/Cellar/rbenv/1.1.2/libexec
     - /Users/bradleywagner/Dev/dotfiles/bin
     - /Users/bradleywagner/.rbenv/shims
     - /usr/local/opt/ant/bin
     - /opt/homebrew/bin
     - /opt/homebrew/sbin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin

@rygr
Copy link

rygr commented Oct 26, 2021

@bradical I know this is going back some time, but curious if you found/remember a solution to your gem issue after modifying the config.status file to install ruby?

@bradical
Copy link
Author

@rygr I think I gave up. I need to go back and look. At some point, I'll either have to revisit it or upgrade the Ruby version and gems for this particular project.

@dataf3l
Copy link

dataf3l commented Aug 28, 2022

@kule thanks, your instructions worked. the process works if people need to install 2.0.0p648 I had the same error:

I tried this:

rvm install ruby-2.0.0-p648

which yielded this:

thread.c:4835:20: error: implicit declaration of function 'rb_frame_last_func' is invalid in C99

so I tried this to solve THAT:

export optflags="-Wno-error=implicit-function-declaration"
rvm install ruby-2.0.0-p648

but I still got this issue:

Error running '__rvm_make install',
please read /Users/b/.rvm/log/1661667543_ruby-2.0.0-p648/install.log
There has been an error while running make install. Halting the installation.

So after reading a bit I tried this command:

echo $PATH|sed 's/:/\r/g'

which in MY computer printed this (notice the ruby 2.7.3 stuff that should not have been there, notice also openssl3, which ruby 2.0.0 doesn't seem to like for some reason:

/Users/b/.rvm/gems/ruby-2.7.3/bin
/Users/b/.rvm/gems/ruby-2.7.3@global/bin
/Users/b/.rvm/rubies/ruby-2.7.3/bin
/Users/b/.rvm/bin
/opt/homebrew/opt/openssl@3/bin
/Users/b/.nvm/versions/node/v14.16.1/bin
/Users/b/.rbenv/shims
/opt/homebrew/opt/libpq/bin
/Users/b/work/_software/google-cloud-sdk/bin
/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/go/bin
/Library/Apple/usr/bin
/Users/b/.cargo/bin

Notice there is a bunch of hardcoded stuff from previous attempts,
So I decided to CLEAN UP the list of folders and come up with this, which looks like a cleaner list.

and run this:

export PATH=/Users/b/.rvm/bin:/Users/b/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

rvm install ruby-2.0.0-p648

Luckily, this means progress, because now I get THIS error (a new error, I interpret as progress):

There has been an error while running make install. Halting the installation.
b@m1 ~ % cat /Users/b/.rvm/log/1661668260_ruby-2.0.0-p648/install.log
+__rvm_make:0> make install
config.status: creating -darwin20.3.0-fake.rb
rm: illegal option -- a
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
config.status: error: could not create -darwin20.3.0-fake.rb
make: *** [-darwin20.3.0-fake.rb] Error 64
+__rvm_make:0> return 2

and now we see that the instructions provided by @kule are in fact correct, except in my case (2.0.0p648) the offending line was not in the same line number, obviously.

I HAD to make sure this was installed and returned something that makes sense:

brew --prefix [email protected]

So finally I tried this:

CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" rbenv install 2.0.0-p648

notice how [email protected] seems to work here, as 1.0 was not available for me.
I kinda thought that openssl1.0 and openssl1.1 would be a super huge conflict, as the instructions I read somewhere wanted 1.0, but it turns out 1.1 worked just fine, I don't know why, this is still a mystery to me.

I guess the issue is probably security, and that using old openssl versions is bad.

I did get this warning:

WARNING: ruby-2.0.0-p648 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

So yeah, no more support, oof.

So I run the program like this, and get the error:

Inspect or clean up the working tree at /var/folders/yv/lystpk8n2015cf8vmqd2yj_c0000gp/T/ruby-build.20220828013423.48747.PAu7Y1
Results logged to /var/folders/yv/lystpk8n2015cf8vmqd2yj_c0000gp/T/ruby-build.20220828013423.48747.log

Last 10 log lines:
Total:      0 (0 undocumented)
  0.00% documented

Elapsed: 0.0s
config.status: creating -darwin20.3.0-fake.rb
rm: illegal option -- a
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
config.status: error: could not create -darwin20.3.0-fake.rb

and after getting the error, I try navigate to the config.status file.

vi /var/folders/yv/lystpk8n2015cf8vmqd2yj_c0000gp/T/ruby-build.20220828013423.48747.PAu7Y1/ruby-2.0.0-p648/config.status

your folder name may vary.

then I proceed to do this, modify this line in line 1086 of config.status.

Replaced:

  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;

With:

  *)  mv "$ac_tmp/out" "$ac_file";;

(this is why one uses rm -- in shell scripts, the use of -- is important I think.

then make, and make install, and the binary is left here:

cd /Users/b/.rbenv/versions/2.0.0-p648/bin
b@m1 bin % ./ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [-darwin20.3.0]
b@m1 bin %

So I was lucky, I hope this helps others.

So here is the history or part of it anyway:


 1000 brew install readline openssl@1

 1013  rvm install ruby-2.0.0-p648
 1014  cat /Users/b/.rvm/log/1661664411_ruby-2.0.0-p648/make.log
 1015  export optflags="-Wno-error=implicit-function-declaration"
 1016  rvm install ruby-2.0.0-p648
 1017  vi /Users/b/.rvm/log/1661667543_ruby-2.0.0-p648/install.log
 1018  echo $PATH
 1020  echo $PATH|sed 's/:/\n/g'
 1021  export PATH=/Users/b/.rvm/bin:/Users/b/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
 1022  rvm install ruby-2.0.0-p648
 1023  cat /Users/b/.rvm/log/1661668260_ruby-2.0.0-p648/install.log
 1025  brew --prefix [email protected]
 1028  CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" rbenv install 2.0.0-p648
 1029  cd /var/folders/yv/lystpk8n2015cf8vmqd2yj_c0000gp/T/
 1031  vi /var/folders/yv/lystpk8n2015cf8vmqd2yj_c0000gp/T/ruby-build.20220828013423.48747.PAu7Y1/ruby-2.0.0-p648/config.status
 1039  make
 1040  make install

let this be a lesson to all of us, we have to let the past go, and move on to a supported ruby 3, where the installation was easy and there wasn't problems.

I wonder how can there be a way where the NEXT user doesn't have to deal with this, no idea how though.

@lopespm
Copy link

lopespm commented May 27, 2024

For anyone else interested this is how I got 2.2.10 to install on m1 mac:

Firstly to get openssl1.0 installed you need a patched version that accounts for the arch (thanks @felixbuenemann):

https://gist.github.com/felixbuenemann/5f4dcb30ebb3b86e1302e2ec305bac89#gistcomment-3567911

Try to install ruby 2.2.10 as per normal in rbenv:

CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" rbenv install 2.2.10

After a while it'll fail as noted by @bradical with:

config.status: creating -darwin20-fake.rb
rm: illegal option -- a
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
config.status: error: could not create -darwin20-fake.rb
make: *** [-darwin20-fake.rb] Error 64

fyi @brandical I also wondered if the -darwin20-fake.rb was an error as usually it'd be something like x86_64-darwin20-fake.rb but I noticed this is just -darwin20-fake.rb with ruby 2.4 and works fine.

Anyways, take a note the debug log directory and go to ruby directory in that path e.g.

$> cd /private/var/folders/yc/_clcptvx4nq0vw_h6frtk0j00000gn/T/ruby-build.20210509110656.28571.vlttTy/ruby-2.2.10

I traced the error in config.status to this line 1097 (fyi $ac_file is -darwin20-fake.rb):

*) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;

It's obviously running the command as if -darwin20-fake.rb are args to the rm command rather than a filename and failing (e.g. simplified it's trying to run rm -rfdarwin20-fake.rb and bailing when it gets to the a in darwin as it's not a valid argument for rm).

There's most probably a better way to do this but for now it worked to just remove the rm -f part of the command:

*) mv "$ac_tmp/out" "$ac_file";;

$> make && make install

voila working 2.2.10 ruby on m1 macs with rbenv.

This solution worked for me, when installing ruby-2.0.0-p648, via ruby-install - in my apple silicon machine, when attempting to install via ruby-install the file causing the issue was config.status, which was located at /Users/<unixname>/src/ruby-2.0.0-p598/config.status. Making the change that @kule suggested, worked for me

Also, it is known that Ruby 2.3 and lower are not compatible with OpenSSL 1.1. So OpenSSL 1.0 may need to be used: #1883 (comment). To install openssl 1.0, you can use brew install rbenv/tap/[email protected]

The steps were:

  1. Run CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])" ruby-install ruby-2.0.0-p598
  2. cd /Users/<unixname>/src/ruby-2.0.0-p598/
  3. Edit config.status, and change *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; into *) mv "$ac_tmp/out" "$ac_file";;
  4. Run make && make install on that folder
  5. ruby-2.0.0-p598 is now available!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants