Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Julessh05/f87c20a921aed1acff4d64183e4c9b80 to your computer and use it in GitHub Desktop.
Save Julessh05/f87c20a921aed1acff4d64183e4c9b80 to your computer and use it in GitHub Desktop.
Using Ruby on Apple M1 (for Cocoapods and Flutter)
In this Gist I will explain you how to use Ruby on Apple M1 Macs.
I will also explain how to use Cocoapods and Flutter with it.
You can use the Files down below, but I would recommend to read the README.md, because it's much prettier in Markdown
I had to use Ruby to work with Flutter Plugins. But Cocoapods won't work on my M1 Mac.
So I surfed the Web, tried out several things, and finally came to a solution.
Most Posts you find online are saying, you should just use your Terminal and Cocoapods with Rosetta.
And of course that works, but it's just a workaround and wasn't enough for me. So you won't need Rosetta in this Solution.
So I tried to figure it out on my own.
Here's what worked for me:
(The Tutorial on how to do the single steps are in the Files below)
- Install Openssl
- Install Libyaml
- Install Ruby
If you need Ruby for Cocoapods and Flutter:
- Using Ruby and Cocoapods with Flutter
Explanation of Terms:
Throughout this Tutorial I'm going to use these Terms:
Pattern:
Term : Explanation
Terminal : You Terminal Application, also called Command Line
Root Password : Your Admin Password. The Password the System Administrator specified when setting up the System. If you don't have that Password, ask your System Administrator.
Rosetta : A Programm, Apple uses on it's M1 Macs, to execute Code, that was compiled for X86 Machines.
[youruserdir] : The Path of your User Directory on your Mac
[yourrcfile] : The RC File for your Terminal
In Order to install Openssl you have to follow these steps:
- Download Openssl: https://www.openssl.org/source/
- Unzip the File
- Open your Terminal
- Go to the Openssl Dir
- Run ./configure
- (I recommend to use --prefix=~/openssl. This installs openssl to a Directory named openssl into your Userdirectory. If it won't work, use --prefix=[youruserdir]/openssl instead.)
- Run make
- Run (sudo) make install (You may need your Root Password)
- You may need sudo, but I would recommend to try it without, because then it's not installed on the complete System, but just on your User
That's it, you downloaded, compiled and installed Openssl into a seperated dir.
Continue with Install Libyaml
If you see the same error message as I did, stating that psych could not be configured, because libyaml is missing or wasn't found (or yaml.h could not be found),
then you most likely have to install libyaml to get rid of that error.
In Order to install libyaml, follow these steps:
- Download Libyaml: https://pyyaml.org/wiki/LibYAML
- Unzip the File
- Open your Terminal (or go back to the Open one from the Previous Step)
- Run ./configure
- (I recommend to use --prefix=~/libyaml. This installs libyaml to a Directory named libyaml into your Userdirectory. If it won't work, use --prefix=[youruserdir]/libyaml instead.)
- Run make
- Run (sudo) make install (You may need your Root Password again.)
- You may need sudo, but I would recommend to try it without, because then it's not installed on the complete System, but just on your User
That's it, you just installed libyaml. Continue with Install Ruby
In Order to Install Ruby you have to follow these steps:
- Download Ruby: https://www.ruby-lang.org/de/downloads/
- Unzip the File
- Open your Terminal (or go back to the Open one from the Previous Step)
- Run ./configure --with-openssl-dir=~/openssl --with-opt-dir=~/libyaml --with-yaml
- (This will configure Ruby with the specified Openssl & Libyaml. If this won't work use ./configure --with-openssl-dir=[youruserdir]/openssl --with-opt-dir=[youruserdir]/libyaml --with-yaml. This will only work, if you specify the exact Paths from the Install Openssl & Install Libyaml Tutorials above. If you specified another Path, while configuring Openssl and/or libyaml, you have to pass these Paths.)
- Credits: Got that --with-opt-dir="" --with-yaml from here: https://stackoverflow.com/a/12361446/16376071
- (I recommend to use --prefix=~/ruby. This installs ruby to a Directory named ruby into your Userdirectory. If it won't work, use --prefix=[youruserdir]/ruby instead.)
- Run make
- Run (sudo) make install (You may need your Root Password again.)
- You may need sudo, but I would recommend to try it without, because then it's not installed on the complete System, but just on your User
That's it, your just downloaded, compiled and installed Ruby.
If you need Ruby for Coccoapods and Flutter continue with Using Ruby and Cocoapods with Flutter.
Otherwise, you should be good to go now.
If you installed all the Frameworks, tools and langues above with a prefix (--prefix="") you may need to update your path.
In Order to do so, follow these steps:
- open your Terminal (or go back to the Open one from the Previous Step)
- Open (or create) the rc file for your shell. Typing echo $SHELL in your Terminal tells you which shell you’re using. If you’re using Bash, edit $HOME/.bash_profile or $HOME/.bashrc. If you’re using Z shell, edit $HOME/.zshrc. If you’re using a different shell, the file path and filename will be different on your machine.
- Credits: https://docs.flutter.dev/get-started/install/macos (I just copied it from there, because it's basically the same)
- create a Ruby Home variable:
- export RUBY_HOME="~/ruby/bin" (or export RUBY_HOME="[youruserdir]/ruby/bin" or any other location you installed ruby)
- I would recommend to use the complete path rather than the "~/" path, just because it works more reliable
- export your new Path:
- export PATH="$RUBY_HOME:$PATH"
- $RUBY_HOME has to appear in front of the $PATH, because otherwise the System will use the old ruby, contained in the $PATH
- Save the file and exit the editor
- reload your terminal (restart or use source [yourrcfile])
- run ruby --version. It should show you newly installed version.
If you need Ruby for Cocoapods and Flutter, like I do, this is for you:
First you have to install Cocoapods. Do this through running this in your Terminal (You don't need Rosetta in this Solution):
- sudo gem install cocoapods (you may need your Root Password again)
After installing Cocoapods, you can use it.
In my case, the Following Error occured:
certificate verify failed (unable to get local issuer certificate)
The Solution for me was to run this in the Terminal:
- pod repo add-cdn main https://cdn.cocoapods.org/
After that I could use Ruby, Cocoapods and Flutter Plugins natively on my M1 Mac.
I once tried to update my Ruby, because the old version got broke by the upgrade from macOS 12 to 13. At least i guess that triggered it.
So I wanted to compile Ruby 3.1.2 and it did not work, it told me, that psych was missing.
Which wasn't a problem before.
The Solution:
I waited for Ruby 3.1.3 to be released and compiled that. The Error was gone.
The lesson i learned is, somethimes if it does not work, just wait for another version to be released :)
A short time later, a new issue arised, whose source I could track to the install process of Ruby 3.1.3. I could install it without psych,
but this was the route of the problem.
So I installed Ruby 3.2.0 with openssl and libyaml and all worked perfectly well.

Summary

I had to use Ruby to work with Flutter Plugins. But Cocoapods won't work on my M1 Mac. So I surfed the Web, tried out several things, and finally came to a solution.

Most Posts you find online are saying, you should just use your Terminal and Cocoapods with Rosetta. And of course that works, but it's just a workaround and wasn't enough for me. So you won't need Rosetta in this Solution.

So I tried to figure it out on my own.

Here's what worked for me: (The Tutorial on how to do the single steps are in the Files above)

  • Install Openssl
  • Install libyaml
  • Install Ruby

If you need Ruby for Cocoapods and Flutter:

  • Using Ruby and Cocoapods with Flutter

Explanation of Terms: Throughout this Tutorial I'm going to use these Terms:

Pattern: Term : Explanation

Terminal : You Terminal Application, also called Command Line
Root Password : Your Admin Password. The Password the System Administrator specified when setting up the System. If you don't have that Password, ask your System Administrator.
Rosetta : A Programm, Apple uses on it's M1 Macs, to execute Code, that was compiled for X86 Machines.
[youruserdir] : The Path of your User Directory on your Mac
[yourrcfile] : The RC File for your Terminal \

Install Openssl

In Order to install Openssl you have to follow these steps:

  • Download Openssl: https://www.openssl.org/source/
  • Unzip the File
  • Open your Terminal
    • Go to the Openssl Dir
    • Run ./configure
      • (I recommend to use --prefix=~/openssl. This installs openssl to a Directory named openssl into your Userdirectory. If it won't work, use --prefix=[youruserdir]/openssl instead.)
    • Run make
    • Run (sudo) make install (You may need your Root Password)
      • You may need sudo, but I would recommend to try it without, because then it's not installed on the complete System, but just on your User

That's it, you downloaded, compiled and installed Openssl into a seperated dir.

Continue with Install Libyaml

Install Libyaml

If you see the same error message as I did, stating that psych could not be configured, because libyaml is missing or wasn't found (or yaml.h could not be found), then you most likely have to install libyaml to get rid of that error.

In Order to install libyaml, follow these steps:

  • Download Libyaml: https://pyyaml.org/wiki/LibYAML
  • Unzip the File
  • Open your Terminal (or go back to the Open one from the Previous Step)
    • Run ./configure
      • (I recommend to use --prefix=~/libyaml. This installs libyaml to a Directory named libyaml into your Userdirectory. If it won't work, use --prefix=[youruserdir]/libyaml instead.)
    • Run make
    • Run (sudo) make install (You may need your Root Password again.)
      • You may need sudo, but I would recommend to try it without, because then it's not installed on the complete System, but just on your User

That's it, you just installed libyaml. Continue with Install Ruby

Install Ruby

In Order to Install Ruby you have to follow these steps:

  • Download Ruby: https://www.ruby-lang.org/de/downloads/
  • Unzip the File
  • Open your Terminal (or go back to the Open one from the Previous Step)
    • Run ./configure --with-openssl-dir=/openssl --with-opt-dir=/libyaml --with-yaml
      • (This will configure Ruby with the specified Openssl & Libyaml. If this won't work use ./configure --with-openssl-dir=[youruserdir]/openssl --with-opt-dir=[youruserdir]/libyaml --with-yaml. This will only work, if you specify the exact Paths from the Install Openssl & Install Libyaml Tutorials above. If you specified another Path, while configuring Openssl and/or libyaml, you have to pass these Paths.)
      • (I recommend to use --prefix=~/ruby. This installs ruby to a Directory named ruby into your Userdirectory. If it won't work, use --prefix=[youruserdir]/ruby instead.)
    • Run make
    • Run (sudo) make install (You may need your Root Password again.)
      • You may need sudo, but I would recommend to try it without, because then it's not installed on the complete System, but just on your User

That's it, your just downloaded, compiled and installed Ruby.

If you need Ruby for Coccoapods and Flutter continue with Using Ruby and Cocoapods with Flutter. Otherwise, you should be good to go now.

Update Path

If you installed all the Frameworks, tools and langues above with a prefix (--prefix="") you may need to update your path.

In Order to do so, follow these steps:

  • open your Terminal (or go back to the Open one from the Previous Step)
  • Open (or create) the rc file for your shell. Typing echo $SHELL in your Terminal tells you which shell you’re using. If you’re using Bash, edit $HOME/.bash_profile or $HOME/.bashrc. If you’re using Z shell, edit $HOME/.zshrc. If you’re using a different shell, the file path and filename will be different on your machine.
  • create a Ruby Home variable:
    • export RUBY_HOME="~/ruby/bin" (or export RUBY_HOME="[youruserdir]/ruby/bin" or any other location you installed ruby)
      • I would recommend to use the complete path rather than the "~/" path, just because it works more reliable
  • export your new Path:
    • export PATH="$RUBY_HOME:$PATH"
      • $RUBY_HOME has to appear in front of the $PATH, because otherwise the System will use the old ruby, contained in the $PATH
  • Save the file and exit the editor
  • reload your terminal (restart or use source [yourrcfile])
  • run ruby --version. It should show you newly installed version.

Using Ruby and Cocoapods with Flutter

If you need Ruby for Cocoapods and Flutter, like I do, this is for you:

First you have to install Cocoapods. Do this through running this in your Terminal (You don't need Rosetta in this Solution):

  • sudo gem install cocoapods (you may need your Root Password again)

After installing Cocoapods, you can use it.

In my case, the Following Error occured: certificate verify failed (unable to get local issuer certificate)

The Solution for me was to run this in the Terminal:

After that I could use Ruby, Cocoapods and Flutter Plugins natively on my M1 Mac.

Important

I once tried to update my Ruby, because the old version got broke by the upgrade from macOS 12 to 13. At least i guess that triggered it. So I wanted to compile Ruby 3.1.2 and it did not work, it told me, that psych was missing. Which wasn't a problem before.

The Solution: I waited for Ruby 3.1.3 to be released and compiled that. The Error was gone. The lesson i learned is, somethimes if it does not work, just wait for another version to be released :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment