iOS开发-安装cocoapods

安装cocoapods

  • 安装cocoapods
    • 1、安装Ruby
    • 2、安装CocoaPods
    • [Which Ruby?](#Which Ruby?)
      • [Why using the macOS system Ruby is bad](#Why using the macOS system Ruby is bad)
    • [Future versions of macOS](#Future versions of macOS)
    • [CocoaPods Installation](#CocoaPods Installation)

安装cocoapods

1、安装Ruby

mac电脑,不要使用系统自带的Ruby(系统自带版本不可升级 ),因为版本旧、违反系统安全

另外,未来苹果会不再内置Ruby

  1. Install Ruby with brew install ruby.

  2. Update $PATH settings in the ~/.zshrc file.

    执行完brew install ruby后,terminal(终端)会显示下面一段话:

    If you need to have ruby first in your PATH, run:

    echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

    根据提示将PATH添加到zshrc就可以了。

go 复制代码
$ open -e ~/.zshrc
然后在打开的.zshrc文件中添加
export PATH="/usr/local/opt/ruby/bin:$PATH"'
保存文件后,执行
$ source ~/.zshrc
最后验证一下
ruby -v

2、安装CocoaPods

CocoaPods官网也不建议使用系统自带的Ruby,建议使用更新版本的Ruby。

Which Ruby?

MacOS comes with a "system Ruby" pre-installed.

Use the which command to see where Ruby is installed:

powershell 复制代码
$ which ruby
/usr/bin/ruby

If you see /usr/bin/ruby, it is the pre-installed macOS system Ruby.

Some developers use the system Ruby for running sysadmin scripts. That's fine, as long as you don't alter the system Ruby by attempting to update or add gems.

For developing projects with Ruby, you should Install Ruby with Homebrew or use a version manager such as asdf, chruby, rbenv, or rvm. A version manager helps if you're juggling multiple projects and can't update all at once. For a guide that compares version managers and shows the best way to install Ruby, see Install Ruby on a Mac.

Why using the macOS system Ruby is bad

Let's take a look at the reasons why it's a bad idea to use the Mac default Ruby for development.

  1. Gem installation problems
  2. Don't violate system security
  3. Gem management
  4. The Mac's old Ruby

Future versions of macOS

Apple says:

"Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won't include scripting language runtimes by default, and might require you to install additional packages."

In future versions, the system Ruby may already be gone (or hidden from you). In that case, you'll need to install Ruby with Homebrew or use a version manager.

CocoaPods Installation

CocoaPods is built with Ruby and it will be installable with the default Ruby available on macOS. However, we recommend not using the system provided Ruby and instead installing a newer Ruby version separate from the system installation. You can use a Ruby Version manager such as RVM or rbenv to manage multiple Ruby versions, or you can use Homebrew to install a newer Ruby with brew install ruby.

相关推荐
游戏开发爱好者86 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
黑码哥7 小时前
ViewHolder设计模式深度剖析:iOS开发者掌握Android列表性能优化的实战指南
android·ios·性能优化·跨平台开发·viewholder
2501_915106328 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106328 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
熊猫钓鱼>_>9 小时前
移动端开发技术选型报告:三足鼎立时代的开发者指南(2026年2月)
android·人工智能·ios·app·鸿蒙·cpu·移动端
徐同保1 天前
通过ip访问nginx的服务时,被第一个server重定向了,通过设置default_server解决这个问题
ios·iphone
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
夏幻灵2 天前
HTTPS全面解析:原理、加密机制与证书体
ios·iphone
TheNextByte12 天前
如何在iPhone上恢复已删除的笔记的综合指南
笔记·ios·iphone