Search code examples
ruby

can't install ruby on m1 macbook air


I tried every method to install ruby (rvm, rbenv, brew) how do I install ruby on m1 MBA?

I used brew to install ruby

dipanshukashyap@Dipanshus-MacBook-Air ~ % brew install ruby
Warning: ruby 3.2.2_1 is already installed and up-to-date.
To reinstall 3.2.2_1, run:
  brew reinstall ruby
dipanshukashyap@Dipanshus-MacBook-Air ~ % ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

it installed ruby but when I check version it gives old version

I used rbenv it gave same problem. (installed, made it global by rbenv global 3.2.2 after installation as instructed but when checked, gives older version)

I used RVM it gives Error running '__rvm_make -j8'


Solution

  • Homebrew Rubies

    Don't do what you're doing. It will eventually cause bad things to happen. Just don't.

    If you insist on juggling chainsaws, then you should create an alias or function to wrap your calls to Ruby in interactive sessions rather than fooling around with the system Ruby, especially in non-interactive shells.

    For example, you can add the following to your ~/.zshrc if you want:

    alias ruby="$(brew --prefix ruby)/bin/ruby"
    

    This approach won't make rvm think it manages that particular Ruby version, but might make it think it's your system Ruby. In any event, you can call the Ruby you think you're calling by putting it first in your PATH.

    RVM Rubies

    The right way to do this is to install Ruby in your home directory (not a system directory) using a Ruby version manager such as RVM. To do that:

    1. Install RVM using the single-user method.
    2. Make sure your shell initialization files are set up properly. This doesn't always happen if you're an advanced user who makes a lot of changes to setup files.
    3. Start a new shell, or call source ~/.rvm/scripts/rvm to load RVM in the current shell.
    4. Install whatever rubies RVM currently supports with rvm list known. See Installing Rubies for more specifics, especially if you're trying to install a patched or non-standard version. NB: Ruby 3.2.2 is still the latest non-preview release that I'm aware of as of this writing.

    RVM, chruby, and rbenv are all good options, and will save you from permissions issues and broken OS dependencies caused by changing the system Ruby or using a brewed binary that may still require additional changes to your environment to work properly. The version managers, when properly installed, avoid those issues for you.