background
Newly joined the company, assigned a brand new MacBook pro, and took this opportunity to sort out the complete installation process of cocoapods.
cocoapods install dependencies
Cocoapods installation requires ruby, updating ruby requires rvm, downloading rvm requires gpg, and downloading gpg requires homebrew, so the installation sequence is homebrew->gpg->rvm->ruby-cocoapods. Note that this is a complete process. If it is just an update, do the cocoapods update operation That's it, you don't need to start from the first step.
1. Install homebrew
Terminal command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Frequently asked questions:
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused This is because of being blocked.
Solution:
Find the ip of raw.githubusercontent.com, and save the mapping relationship in the host file.
-
Open the website https://www.ipaddress.com/
to check the IP address corresponding to raw.githubusercontent.com. The IP address found here is: 199.232.68.133 -
Modify the host file
Terminal input:sudo vim /etc/hosts
Prompt to enter the MAC account password
to save the mapping relationship
- Enter the initial installation command in the terminal.
2. Use homebrew to install gpg
Terminal command:
brew install gnupg
3. Install rvm
Terminal command:
- first step
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
- second step
curl -sSL https://get.rvm.io | bash -s stable
It often appears here, mac zsh:gpg: Unable to check signature: No public key problem, the terminal will prompt, and execute the command according to the prompt terminal gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
to solve this problem.
- The third step
terminal execution
source ~/.bashrc
source ~/.bash_profile
After installing rvm, check the version of rvm, command: rvm -v
, rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
if it is displayed, rvm installation is successful.
4. Install ruby
Terminal executes:
rvm list known
Check the version of ruby, all the versions in the list can be used for installation, and all the versions in the list can be installed, pay attention to choose a stable version, it is not recommended to install the test version. I installed version 2.6.5 here
rvm install 2.6.5
After the download is complete, execute:
rvm use 2.6.5 --default // 将2.6.5设为默认版本
If it appears:
Failed to update Homebrew, follow instructions at
https://docs.brew.sh/Common-Issues
and make sure brew update
works before continuing.
Continue to execute: brew install ruby
Updating Homebrew... Error: readline: undefined method
undent' for #String:0x00007fd7d955c130`
rvm autolibs read-only
, then install:rvm install ruby-2.6.5
View installed ruby
rvm list
replace source
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
Verify that the mirror source is installed successfully:gem sources -l
5. Install cocopods
sudo gem install -n /usr/local/bin cocoapods
Install local library
pod setup
Note: In the new version of macOS system, executing the pod setup command on the system command line will end directly;
the solution is to manually install the local library
and execute:
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
// 接下来就是漫长的等待时间
// 这个命令等待几分钟不一定成功,注意不是错误,是网络问题,重新执行即可。
// 要想网速快点,可以用移动网络,或者等到晚上凌晨。
// 另外也可以使用国内的镜像,速度有明显改善,命令如下:
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
if it still doesn't work
// 安装最新版cocoapods
sudo gem install cocoapods --pre
// 移除本地master
sudo rm -fr ~/.cocoapods/repos/master
// 移除本地缓存
sudo rm -fr ~/Library/Caches/CocoaPods/
// 重新setup,如果很慢可使用问题1的解决方法(git clone)
pod setup --verbose
// 移除trunk
pod repo remove trunk
After the download is complete, check whether it is available. You can find any third-party library. Here, take AFNetworking as an example.
pod search AFNetworking
Six, the specific use of cocoapods
Create a new Xcode project, use the terminal cd to the project directory
- Create a Podfile:
pod init
- Open Podfile:
open Podfile
- Add to:
pod 'AFNetworking'
save and launch
- Install:
pod install
This is the end of the whole process. If there is something to add, you can leave a message, and I will add it here.