cli: CLI doesn't detect Cococapods installed via rbenv.
Environment
> rbenv --version
rbenv 1.2.0
> ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
> pod --version
1.11.3
> which pod
/Users/christopher.araujo/.rbenv/shims/pod
> node --version
v16.16.0
Description
The React Native CLI does not seem to detect Cocoapods installed via RubyGems managed by rbenv. The CLI prompts me to install Cocoapods. However, selecting Yes, with gem (may require sudo)
throws an error.
✔ CocoaPods (https://cocoapods.org/) is not installed. CocoaPods is necessary for the iOS project to run correctly. Do you want to install it? › Yes, with gem (may require sudo)
✖ Installing CocoaPods
error
✖ Installing CocoaPods
error Error: An error occured while trying to install CocoaPods, which is required by this template.
Please try again manually: sudo gem install cocoapods.
Reproducible Demo
Run npx react-native init MyFirstRNProject
on a machine that has Cocoapods installed via RubyGems managed by rbenv.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 21 (4 by maintainers)
For anyone else having problems with rbenv and cocoapods, I got through this by:
pod
since rbenv shim kept taking over and I’m not sure I want to go around deleting all the cocoapods installed on different ruby versions.alias pod="/opt/homebrew/bin/pod"
After running
npx react-native init Project
, I see there is a.ruby-version
file in the project that is setting the ruby version to 2.7.5. I do not have this version of ruby installed. I have been using 3.0.2. Seems like this could be an issue ifreact-native
cli is supposed to use your rbenv selected ruby version.I just gave up installing my project with RN version 0.70. Impossible to install Bundler because of the Ruby version, impossible to make any Ruby version manager work
also having this problem. already have cocoapods installed on version of ruby that is set via rbenv. m1 mac. running
sudo gem install cocoapods
does not help.I was trying to be a good little boy by installing a Ruby version manager (rbenv
) like the docs suggest, even though I know I didn’t install a Ruby manager in the past. Cue a multi-hour-long nightmare. In the end I uninstalledrbenv
, and my problems magically disappeared:rbenv versions
(identify the non-system
Ruby version #)sudo rbenv uninstall 2.7.6
(of course replace2.7.6
with your non-system
Ruby version #)rbenv global system
rbenv local system
rbenv versions
(confirm thesystem
Ruby version is selected & the non-system
version is uninstalled/unlisted)~~https://stackoverflow.com/a/63885864/3511695~~brew uninstall rbenv
What a waste of time. Will avoid using Ruby version managers in the future.Also, at the time of writing, theruby-version
file they link to in their official docs currently says Ruby2.7.6
, so that’s the version I installed withrbenv
because, again, that’s what the docs told me to do. But when I ranreact-native init
, the ruby version that was placed into the project’s.ruby-version
file was instead2.7.5
. So that was infuriating. (Maybe if I instead installed2.7.5
withrbenv
like the docs should have told me to, I wouldn’t have run into these issues in the first place.)In place of linking to the ruby-version file on the livemain
branch in their Environment Setup doc, they should instead be linking to the ruby-version file from thelatest
RN release because (of course) the latest version of RN is what thenpx react-native init
command is going to end up using!! (Just created a Pull Request)EDIT: Yeah I had to start over with 0.70.4 and just installed the the ruby-version file from the
latest
RN release instead of the ruby-version file on the livemain
branch and it workedAs other people mentioned, if you are using
rbenv
(highly recommend) and your list of installed Rubies does not contain the version from.ruby-version
file then CLI instead of telling you that your environment does not have a Ruby version required by a template just tries to findpod
executable so the the output of CLI is misleading. There is a trick: if you are quick enough you can runnpx react-native init
and right after that go to the directory and edit the.ruby-version
file so that it contain a version that you have installed 😂 So by the time when CLI will try to install pods the.ruby-version
content will be correct for your env. Ideally CLI should test whether required Ruby version present.Just install ruby using rvm instead of rbenv its life saving. https://nrogap.medium.com/install-rvm-in-macos-step-by-step-d3b3c236953b
@liamjones Right~ The problem is, the cli would not download ruby or cocoapods of specific version. Maybe the CLI scripts could do a little more…