美文网首页
cocoapods安装问题

cocoapods安装问题

作者: 突刺刺 | 来源:发表于2021-06-21 17:31 被阅读0次

CocoaPods简介

  • CocoaPods是一个用Ruby写的、负责管理iOS项目中第三方开源库的工具,CocoaPods能让我们集中的、统一管理第三方开源库,为我们节省设置和更新第三方开源库的时间。
  • Mac电脑自带Ruby环境。
  • CocoaPods需要最低Ruby环境,可以升级Ruby版本。

CocoaPods安装

1. 安装Homebrew,通过Homebrew升级ruby版本

  • 使用国外资源安装raw.githubusercontent.com:
    • 终端键入
     /bin/bash -c "$(curl -fsSL    https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    • 报错:Failed to connect to raw.githubusercontent.com port 443:之类的错误
    • 解决:
    • 系统偏好设置->网络->选择当前连接的网络->高级->DNS->添加+8.8.8.8114.114.114.114->设置完成一定要点击应用
    • 终端键入nslookup,显示如下:
      lhzl_lgq@LHZLdeMac-mini ~ % nslookup
      > raw.githubusercontent.com
      Server:        114.114.114.114
      Address:   114.114.114.114#53
    
      Non-authoritative answer:
      Name:  raw.githubusercontent.com
      Address: 185.199.108.133
      Name:  raw.githubusercontent.com
      Address: 185.199.111.133
      Name:  raw.githubusercontent.com
      Address: 185.199.109.133
      Name:  raw.githubusercontent.com
      Address: 185.199.110.133
      > 
    
    • ping一下四个IP,选择延迟最快的,copy
    • 终端键入vi /etc/hosts:
      ##
      # Host Database
      #
      # localhost is used to configure the loopback interface
      # when the system is booting.  Do not change this entry.
      ##
      127.0.0.1       localhost
      255.255.255.255 broadcasthost
      ::1             localhost
      
      # GitHub Start
      185.199.111.133   raw.githubusercontent.com   #(这个IP就是上面copy的)
      # GitHub End
      ~                                                                                                                                                                                                                                         
      "/etc/hosts" 13L, 286C
      
    • Esc退出vim编辑模式,:wq退出vim
    • 重新键入
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    • 安装成功
    • curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443,报这个错,直接换国内源安装。
  • 如果使用国外源不成功,可以使用国内源安装Homebrew:
    • 终端键入:
      /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
      
    • 安装成功

2.安装rvm,通过rvm升级ruby版本

  • 键入
curl -L get.rvm.io | bash -s stable
  • 如果报错curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused,则按照上面安装Homebrew国外源的办法,设置DNS和修改/etc/hosts
  • 下载完成,加载 RVM后才能使用。键入
source ~/.rvm/scripts/rvm
  • 检查安装是否成功
rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

3.安装ruby

  • 使用RVM工具安装 Ruby
// 列出已知的ruby版本
rvm list known
// 安装 x.x.x为Ruby版本号
rvm install 3.0.0
  • 使用Homebrew工具安装 Ruby
brew install ruby
  • 查看ruby版本
ruby -v
  • 更换ruby源
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
gem sources -l #查看当前源

4.安装cocoapods

  • 安装CocoaPods
    sudo gem install -n /usr/local/bin cocoapods
    
  • 安装本地库
    pod setup
    

相关文章

网友评论

      本文标题:cocoapods安装问题

      本文链接:https://www.haomeiwen.com/subject/tbmyyltx.html