Installing Ruby with Homebrew
in ~/.bash_profile
add the following line
export PATH=/usr/local/Cellar/ruby/1.9.3-p194/bin:$PATH
When you're done, close your terminal and re-open it. You should be fine.
Alternatively, you can execute the follwing in each open shell instead of closing/re-opening:
source ~/.bash_profile
Note:
I highly recommend installing ruby via rvm or rbenv so you can manage multiple ruby versions and use gemsets.
Need help installing Ruby 2.7.2 on Mac
You need to install the latest ruby-build
$ brew unlink ruby-build # remove STABLE version
$ brew install --HEAD ruby-build
$ rbenv install -l | grep '2.7.2'
2.7.2
Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all' to show all local versions.
How to use the Homebrew's Ruby package instead of the Ruby package that comes with MacOS?
Figured out my mistake.
export PATH="/usr/local/Cellar/ruby/2.6.1/bin/ruby:$PATH"
Should have been
export PATH="/usr/local/Cellar/ruby/2.6.1/bin:$PATH"
then just run
source ~/.bash_profile
and confirm with ruby -v
or type -a ruby
How to update Ruby with Homebrew?
brew upgrade ruby
Should pull latest version of the package and install it.
brew update
updates brew itself, not packages (formulas they call it)
Install ruby with asdf on MacOS via Homebrew
I am facing same situation. It seems to be fixed soon.
https://github.com/asdf-vm/asdf-ruby/issues/239
Edit ~/.asdf/plugins/ruby/bin/install
and apply this patch then the problem is fixed for me.
- if [[ -n "$matching_version" ]]; then
+ if [[ -z "$matching_version" ]]; then
How can I switch to ruby 1.9.3 installed using Homebrew?
I suggest you take a look at rvm.
You can then set it as default with rvm use 1.9.3 --default
But if you are happy with your homebrew install.
Then just change the precedence of directories in the PATH
Here is my /etc/paths
# homebrews should always take precedence
/usr/local/bin
# the default stack
/usr/bin
/bin
/usr/sbin
/sbin
This is important generally for homebrew, else the system version of git, ruby, pg_admin,... will all be used instead of the brew version.
if you say which -a ruby
you'll see all the installed rubies, and the precedence in the PATH
eg.
$ which -a ruby
/Users/matthew/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
/Users/matthew/.rvm/bin/ruby
/usr/bin/ruby
UPDATE: I now don't think you should change
/etc/paths
Instead you need to check which of .profile
, .bashrc
, or .bash_login
is being loaded in your shell, and just add /usr/local/bin
to your path.
For me, I only have a .profile
. You can create that file if none of those files already exist in your home directory.
# homebrews should always take precedence
export PATH=/usr/local/bin:$PATH
Install older Ruby versions on a M1 MacBook?
In order to make installing of Ruby versions 2.6.x or 2.7.x successful on M1 MacBook using either rbenv
or asdf
(asdf is used in this example) follow these steps:
Upgrade to the latest version of rbenv
or asdf-ruby
plugin using your prefered installation method. In my case it's asdf-ruby
installed over homebrew:
brew upgrade asdf
asdf plugin update ruby
Reinstall the current versions of openssl
, readline
and ruby-build
in order to have the latest versions and configs:
brew uninstall --ignore-dependencies readline
brew uninstall --ignore-dependencies openssl
brew uninstall --ignore-dependencies ruby-build
rm -rf /opt/homebrew/etc/openssl@1.1
brew install -s readline
brew install -s openssl
brew install -s ruby-build
In your shell config .bashrc
or .zshrc
add the following ENV variables:
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
export LDFLAGS="-L/opt/homebrew/opt/readline/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/readline/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig:$PKG_CONFIG_PATH"
export optflags="-Wno-error=implicit-function-declaration"
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
This will ensure that the proper libraries and headers are used during the installations and it will ignore the implicit-function-declaration
that is preventing some versions to continue installation. Note that for some other shells like fish
the exporting of these variables will be a bit different.
Now start a new terminal session and you can try installing the older ruby versions:
asdf install ruby 2.7.2
asdf install ruby 2.6.5
Note that really old versions below 2.5 might still have issues. Most of the credits go to this Github issue.
UPDATE
For Ruby 2.2 please change the following variable:
export RUBY_CONFIGURE_OPTS=openssl@1.0
And do a
asdf reshim ruby
Thanks @xjlin0 for this update
Related Topics
"Whenever" Gem Running Cron Jobs on Heroku
Why Is _File_ Uppercase and _Dir_ Lowercase
Emacs Is Ignoring My Path When It Runs a Compile Command
Looping Through an Array with Step
Ruby: Accessing Rake Task from a Gem Without Rails
How to Have Multiple Versions of Ruby and Rails, and Their Combinations on Windows
Get Current Ruby Process Memory Usage
Monkey Patching Devise (Or Any Rails Gem)
Rails Forms for Has_Many Through Association with Additional Attributes
Dividing Elements of a Ruby Array into an Exact Number of (Nearly) Equal-Sized Sub-Arrays
Add Method to an Instanced Object
Getting an Ascii Character Code in Ruby Using '' (Question Mark) Fails
How to Unzip a File in Ruby on Rails
Using Implicit 'Subject' with 'Expect' in Rspec-2.11
How to Uninstall Ruby from /Usr/Local