前提:要翻墙开启终端代理
一、MAC终端配置代理
二、删除cocoapods
三、安装cocoapods
Mac终端代理配置
1、配置命令
在 ~/.bash_profile
或 ~/.zshrc
文件中(这两个文件,选一个即可),添加如下代码:
function proxy_off() {
unset http_proxy
unset https_proxy
unset ftp_proxy
unset rsync_proxy
echo -e "已关闭代理"
}
function proxy_on() {
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export http_proxy="http://127.0.0.1:1087"
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export FTP_PROXY=$http_proxy
export RSYNC_PROXY=$http_proxy
echo -e "已开启代理"
}
其实精简版只需要下面即可:
# 设置代理
function proxy_on() {
export all_proxy="socks5://127.0.0.1:7890"
export no_proxy="localhost, 127.0.0.1, localaddress, .localdomain.com"
echo -e "已开启代理..."
}
function proxy_off() {
unset all_proxy
echo -e "已关闭代理!"
}
注意:关于端口号是 7890
还是 7891
,需要看【从代理软件中复制的「复制终端代理命令」是什么值】。
2、立刻生效
执行 source ~/.bash_profile
或 source ~/. zshrc
,使其立刻生效。
3、启动与关闭
需要使用代理时打开终端,输入proxy_on
代理就会启动。如果需要关闭,只需要输入proxy_off
。
注:该设置仅对当前终端窗口生效,关闭该终端窗口后失效。
卸载cocoapods
卸载老版本cocoapods
$ sudo gem uninstall cocoapods
查看本地安装过的cocopods相关东西
gem list --local | grep cocoapods
显示如下:
cocoapods-core (1.9.1)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.3.0)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.4.1)
cocoapods-try (1.1.0)
然后使用命令逐个删除
$ sudo gem uninstall cocoapods-core
如果怕删不干净有残留的话可以找到 .cocopods 文件(显示隐藏文件快捷键command + shift + .)删掉就好
重新安装cocoapods
安装顺序
homebrew —> rvm —> ruby —> cocoapods
1、安装brew
官网介绍: https://brew.sh/index_zh-cn
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
$ brew search wget
==> Formulae
wget
$ brew install wget
$ brew list
autoconf openssl@1.1 pkg-config rbenv readline ruby-build
2、 brew安装rvm
$ curl -L https://get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 194 100 194 0 0 148 0 0:00:01 0:00:01 --:--:-- 148
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
解决以上报错:
sudo chmod 777 /etc/hosts
vi /etc/hosts
添加如下homebrew的网址主机映射
# 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
199.232.68.133 raw.githubusercontent.com
回到终端重新执行rvm安装命令
$ curl -L https://get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 194 100 194 0 0 149 0 0:00:01 0:00:01 --:--:-- 149
100 24535 100 24535 0 0 10864 0 0:00:02 0:00:02 --:--:-- 48013
Downloading https://github.com/rvm/rvm/archive/1.29.10.tar.gz
......
Installation of RVM in /Users/stevenwu/.rvm/ is almost complete:
* To start using RVM you need to run `source /Users/stevenwu/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.
👉 Donate: https://opencollective.com/rvm/donate
载入 RVM 环境
$ source ~/.rvm/scripts/rvm
检查一下是否安装正确
$ rvm -v
rvm 1.29.10 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
rvm安装ruby
安装ruby前务必先安装Homebrew
可以先查询已经安装的ruby
$ rvm list
如果有安装过,则先卸载已安装版本
$ rvm remove 1.9.2
列出已知的ruby版本
$ rvm list known
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.9]
[ruby-]2.5[.7]
[ruby-]2.6[.5]
[ruby-]2.7[.0]
ruby-head
开始安装ruby
$ rvm install 2.6.5
检测是否正确
$ ruby -v
$ gem -v
设置Ruby默认版本
RVM 装好以后,需要执行下面的命令将指定版本的 Ruby 设置为系统默认版本
$ rvm 2.0.0 --default
同样,也可以用其他版本号,前提是你有用 rvm install 安装过那个版本
切换gem下载源:
$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l
https://gems.ruby-china.com
# 确保只有 gems.ruby-china.com
4、安装cocoapods
$ sudo gem install cocoapods 差不多过个几十秒吧
$ pod setup
Terminal会停留在 Setting up CocoaPods master repo 这个状态一段时间,是因为要进行下载安装,而且 目录比较大,需要耐心等待一下
如果一直失败,如尝试如下命令
cd ~/.cocoapods/repos/master
git clone https://git.coding.net/CocoaPods/Specs.git
测试一下:
$ pod search Masonry
-> Masonry (1.1.0)
Harness the power of Auto Layout NSLayoutConstraints with a simplified, chainable and expressive syntax.
pod 'Masonry', '~> 1.1.0'
- Homepage: https://github.com/cloudkite/Masonry
- Source: https://git.100tal.com/tal_internal_pods/Masonry.git
- Versions: 1.1.0 [100tal-tal_internal_pods-talinternalpodrepo repo]
-> Masonry+LayoutGuideExt (0.1.0)
A short description of Masonry+LayoutGuideExt.
pod 'Masonry+LayoutGuideExt', '~> 0.1.0'
- Homepage: https://github.com/inspiredtips/Masonry-Extension
- Source: https://github.com/inspiredtips/Masonry-Extension
- Versions: 0.1.0 [cocoapods repo]
-> masonry+superview (0.2.0)
masonry+superview
pod 'masonry+superview', '~> 0.2.0'
- Homepage: https://github.com/xuk3r/masonry-superview
- Source: https://github.com/xuk3r/masonry-superview.git
- Versions: 0.2.0, 0.1.1, 0.1.0, 0.0.2 [cocoapods repo]
-> Masonry+ToSuperView (0.2.0)
masonry+superview
pod 'Masonry+ToSuperView', '~> 0.2.0'
- Homepage: https://github.com/xuk3r/masonry-superview
- Source: https://github.com/xuk3r/masonry-superview.git
- Versions: 0.2.0, 0.1.0, 0.0.2 [cocoapods repo]
:
感谢 stevenwu
,参考地址:http://stevenwuzheng.com/archives/pods
网友评论