0

I am not really a ruby, cocoapods user. They are just required dependencies to other softwares which I use.

First, let me describe my current weird environment. Somehow, brew 2.2.6 doesn't allow me to link latest ruby to /usr/local with the error msg Warning: Refusing to link macOS-provided software.

$ /usr/bin/ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

$ /usr/local/opt/ruby/bin/ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]

After googling, I don't know what the best way to handle this situation is . So I decided to follow what brew suggests:

my .bash_profile:

export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH="${PATH}:/usr/local/lib/ruby/gems/2.7.0/bin"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/ruby/lib/pkgconfig"

After the above setup, now I am trying to update cocoapods.

$ sudo gem install cocoapods
Successfully installed cocoapods-1.8.4

$ pod setup

$ pod --version
1.5.3

$ gem which cocoapods
/usr/local/lib/ruby/gems/2.7.0/gems/cocoapods-1.8.4/lib/cocoapods.rb

$ which pod
/usr/local/bin/pod

$ ls -l /usr/local/bin/pod
lrwxr-xr-x  1 user  admin  33 Aug  5  2018 /usr/local/bin/pod -> ../Cellar/cocoapods/1.5.3/bin/pod

You can see that I have cocoapods-1.8.4 installed, but pod always tells me I am using 1.5.3.

After finding the pod executable file, finally, I figured out the following will work by reordering the PATHs:

$ export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"

$ which pod
/usr/local/lib/ruby/gems/2.7.0/bin/pod

$ pod --version
1.8.4

But, is this recommended way to handle this situation?

I really don't like there are two ruby and pod versions on my system. I don't use ruby at all personally. It's just a dependency to my other apps.

Updated: My Current Solution

After a few days I posted this question, I finally end up having three ruby versions in my system... But it's working fine so I will live with it for now.

First, I uninstall ruby related apps/formula from brew:

$ brew uninstall macvim
$ brew uninstall ruby cocoapods

I uninstall macvim because that depends on ruby. And I also remove all exports from .bash_profile.

Second, I install rvm and use rvm to install ruby:

$ curl -L https://get.rvm.io | bash -s stable  # install rvm
$ rvm install ruby-2.7.0

Third, install cocoapods by gem

$ sudo gem install cocoapods
$ pod setup

Fourth, install macvim back by brew

$ brew install macvim

but, unfortunately even if I have the latest ruby installed by rvm on the path, brew still install its own ruby 2.7.0 again....

So in the end, I have three rubies:

$ /usr/bin/ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

$ /usr/local/opt/ruby/bin/ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]

$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]

$ which ruby
/Users/<user>/.rvm/rubies/ruby-2.7.0/bin/ruby

Well, I think this should be fine. I don't need to export anything manually by myself and rvm will handle it for me.

You must log in to answer this question.

Browse other questions tagged .