I am trying to install cocoapods on my MacBook Pro (Retina, 15-inch, Mid 2015) running a mac-os of Monterey version 12.6.1 using $ sudo gem install cocoapods
on the terminal but it gives the following error.
apple@APPLEs-MBP ~ % sudo gem install cocoapods
Password:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.
/Library/Ruby/Site/2.6.0/rubygems/installer.rb:712:in `verify_gem_home'
/Library/Ruby/Site/2.6.0/rubygems/installer.rb:902:in `pre_install_checks'
/Library/Ruby/Site/2.6.0/rubygems/installer.rb:302:in `install'
/Library/Ruby/Site/2.6.0/rubygems/resolver/specification.rb:104:in `install'
/Library/Ruby/Site/2.6.0/rubygems/request_set.rb:194:in `block in install'
/Library/Ruby/Site/2.6.0/rubygems/request_set.rb:182:in `each'
/Library/Ruby/Site/2.6.0/rubygems/request_set.rb:182:in `install'
/Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:210:in `install_gem'
/Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:226:in `block in install_gems'
/Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:219:in `each'
/Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:219:in `install_gems'
/Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:167:in `execute'
/Library/Ruby/Site/2.6.0/rubygems/command.rb:323:in `invoke_with_build_args'
/Library/Ruby/Site/2.6.0/rubygems/command_manager.rb:185:in `process_args'
/Library/Ruby/Site/2.6.0/rubygems/command_manager.rb:149:in `run'
/Library/Ruby/Site/2.6.0/rubygems/gem_runner.rb:51:in `run'
/usr/bin/gem:21:in `<main>'
apple@APPLEs-MBP ~ %
I am Using Xcode 14.1 (14b47b) and I also checked that the command line tools is also present and using a similar version. I have tried to install via Homebrew but when following the instruction at some point it ask me to install command line tools again. I still do this despite having the most recent version installed and after complete download it just do nothing. I have tried this process more than 10 times already.
When i use this code sudo gem update --system
it says latest version already installed. I have tried everything on stack-overflow it still will not work.
CodePudding user response:
I have finally resolved the error and I am posting the processes used incase someone faces the exact same issue.
Firstly I ran
% ruby -v
and% which ruby
with terminal and took note of my ruby version and path (This was the default Mac ruby).I downloaded Command line tools
version 14.1
from https://developer.apple.com This version was the same version as my xcode and it was already installed with xcode but I download and installed anyway.After the successful installation of the Command line tool, I moved on to download Hombrew and after the install was successful, I then installed the cocoapods using
% brew install cocoapods
in terminal. At this point point cocoapods was installed but not properly working. as it was giving an error about 40 gems and some manifest not found.This prompt me to install ruby with
% brew install ruby
and after taking some time it was installed successfully with some instructions on how to change the default ruby to the newly installed ruby. The instructions where to run the following code in terminal.echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc $ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.zshrc $ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.zshrc $ source ~/.zshrc
After doing step 4, run
% ruby -v
and% which ruby
and you will see that your ruby path and ruby version has been changed.Lastly I then installed Cocoapods using this
% sudo gem install -n /usr/local/bin cocoapods
and it was all installed successfuly.