ios 如何安装cocoapods?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20755044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install cocoapods?
提问by kagmanoj
I referred too many links and tried, but had no success. If any one has an idea then please please share with me. I read cocoa pods documents and many times tried to install but always failed because of the starting steps. I found one error whereby I can't install gems first. Can anyone give me the steps one by one? How to install or demo.
我参考了太多链接并尝试过,但没有成功。如果有人有任何想法,请与我分享。我阅读了 cocoa pods 文档,并多次尝试安装,但由于启动步骤总是失败。我发现了一个错误,我无法先安装 gems。谁能一一给我步骤?如何安装或演示。
Thisis one link which I tried.
这是我尝试过的一个链接。
The screen shot refers to this console error I was given:
屏幕截图指的是我收到的这个控制台错误:
回答by Om Prakash
POD Install
POD 安装
[ 1 ] Open terminal and type:
[ 1 ] 打开终端并输入:
sudo gem install cocoapods
Gem will get installed in Ruby inside System library. Or try on 10.11 Mac OSX El Capitan, type:
Gem 将安装在系统库中的 Ruby 中。或者在 10.11 Mac OSX El Capitan 上试试,输入:
sudo gem install -n /usr/local/bin cocoapods
If there is an error "activesupport requires Ruby version >= 2.xx", then install latest activesupport first by typing in terminal.
如果出现错误“activesupport requires Ruby version >= 2.xx”,则首先通过在终端中键入来安装最新的 activesupport。
sudo gem install activesupport -v 4.2.6
[ 2 ] After installation, there will be a lot of messages, read them and if no error found, it means cocoapods installation is done. Next, you need to setup the cocoapods master repo. Type in terminal:
[ 2 ] 安装完成后,会有很多提示信息,仔细阅读,如果没有发现错误,说明cocoapods安装完成。接下来,您需要设置 cocoapods 主存储库。输入终端:
pod setup
pod setup
And wait it will download the master repo. The size is very big (370.0MB at Dec 2016). So it can be a while. You can track of the download by opening Activity and goto Network tab and search for git-remote-https. Alternatively you can try adding verbose to the command like so:
等待它下载主存储库。大小非常大(2016 年 12 月为 370.0MB)。所以可能需要一段时间。您可以通过打开活动并转到网络选项卡并搜索 git-remote-https 来跟踪下载。或者,您可以尝试向命令添加详细信息,如下所示:
pod setup --verbose
pod setup --verbose
[ 3 ] Once done it will output "Setup Complete", and you can create your XCode project and save it.
[ 3 ] 完成后将输出“Setup Complete”,您可以创建您的 XCode 项目并保存它。
[ 4 ] Then in terminal cd to "your XCode project root directory" (where your .xcodeproj
file resides) and type:
[ 4 ] 然后在终端 cd 到“您的 XCode 项目根目录”(您的.xcodeproj
文件所在的位置)并键入:
pod init
pod init
[ 5 ] Then open your project's podfile by typing in terminal:
[ 5 ] 然后通过在终端中键入来打开项目的 podfile:
open -a Xcode Podfile
open -a Xcode Podfile
[ 6 ] Your Podfile will get open in text mode. Initially there will be some default commands in there. Here is where you add your project's dependencies. For example, in the podfile, type
[ 6 ] 您的 Podfile 将以文本模式打开。最初会有一些默认命令在那里。您可以在此处添加项目的依赖项。例如,在 podfile 中,键入
pod 'AFNetworking', '0.9.1'
pod 'AFNetworking', '0.9.1'
(this line is an example of adding the AFNetworking library to your project).
(这一行是将 AFNetworking 库添加到您的项目的示例)。
Other tips:
其他提示:
Uncomment platform :ios, '9.0'
Uncomment user_frameworks!
if you're using Swift
如果您使用的是 Swift,请取消 platform :ios, '9.0'
注释 user_frameworks!
When you are done editing the podfile, save it and close Xcode.
完成 podfile 的编辑后,保存并关闭 Xcode。
[ 7 ] Then install pods into your project by typing in terminal:
[ 7 ] 然后通过在终端中键入将 pod 安装到您的项目中:
pod install
pod install
Depending how many libraries you added to your podfile for your project, the time to complete this varies. Once completed, there will be a message that says
根据您为项目添加到 podfile 的库数量,完成此操作的时间会有所不同。完成后,会有一条消息说
"Pod installation complete! There are X dependencies from the Podfile and X total pods installed."
“Pod 安装完成!Podfile 中有 X 个依赖项,总共安装了 X 个 Pod。”
Now close your Xcode project. Then locateand open the .xcworkspace
Xcode project file and start coding. (You should no longer open the xcodeproj
file)
现在关闭您的 Xcode 项目。然后找到并打开.xcworkspace
Xcode 项目文件并开始编码。(您不应再打开该xcodeproj
文件)
回答by RakeshDipuna
1.First open your terminal
1.首先打开你的终端
2.Then update your gem file with command
2.然后用命令更新你的gem文件
sudo gem install -n /usr/local/bin cocoapods
3.Then give your project path
3.然后给出你的项目路径
cd /your project path
4.Touch the podifle
4. 触摸 podifle
touch podfile
5.Open your podfile
5.打开你的podfile
open -e podfile
6.It will open a podfile like a text edit. Then set your target. For example if you want to set up Google maps then your podfile should be like
6.它将像文本编辑一样打开一个podfile。然后设定目标。例如,如果你想设置谷歌地图,那么你的 podfile 应该像
use_frameworks!
target 'yourProjectName' do
pod 'GoogleMaps'
end
7.Then install the pod
7.然后安装pod
pod install
回答by Jayesh Mardiya
This works for OS X El Capitan 10.11.x
这适用于 OS X El Capitan 10.11.x
sudo gem install -n /usr/local/bin cocoapods
在此之后,您可以使用 pod setup cmd 设置 pod,然后移动到您的项目目录并安装 pod
回答by onCompletion
These are the complete steps that I usually follow. I am posting this steps as short as possible and assuming that you know about Mac and Xcode projects. First of all, open the terminal and use the following commands, and press enter after each command.
这些是我通常遵循的完整步骤。我将尽可能简短地发布这些步骤,并假设您了解 Mac 和 Xcode 项目。首先,打开终端并使用以下命令,并在每个命令后按回车。
Type in the following command if you don't already have CocoaPods installed:
如果您还没有安装 CocoaPods,请输入以下命令:
sudo gem install cocoapods
Now please move to your Xcode Project directory by using this following command, and replace /Your Xcode Project Directory Path
with the actual path to the directory:
现在请使用以下命令移动到您的 Xcode 项目目录,并替换/Your Xcode Project Directory Path
为目录的实际路径:
cd /Your Xcode Project Directory Path
Below are instructions for how to use CocoaPods. Please wait for some time after each and every command entered to the terminal to execute successfully.
以下是如何使用 CocoaPods 的说明。每条命令输入到终端后,请等待一段时间以成功执行。
- Searching for pods in terminal:
- 在终端中搜索 Pod:
pod search networking
(replace networking with which you want to search)
pod search networking
(替换您要搜索的网络)
- Creating the pod file:
- 创建 pod 文件:
pod init
pod init
- Opening the pod file:
- 打开 pod 文件:
open -a Xcode Podfile
open -a Xcode Podfile
- Adding the pods: (After adding your pods you must save the podfile first and then head back to the terminal again.)
- 添加 pod:(添加 pod 后,您必须先保存 podfile,然后再次返回终端。)
target 'WebServiceUsingMantleAFNetworking' do
# platform :ios, '8.0' //Choose your version of iOS
pod 'AFNetworking', '~> 2.6.0'
end
OR
或者
platform :ios, '8.0'
pod 'AFNetworking'
pod 'Mantle'
pod 'LBBlurredImage'
pod 'TSMessages'
pod 'ReactiveCocoa'
- Installing the pods:
- 安装 Pod:
pod install
pod install
- Check for updates of pods on existing project:
- 检查现有项目上 pod 的更新:
pod outdated
pod outdated
- Update the existing pods:
- 更新现有的 pod:
pod update
pod update
- Uninstall the Cocoapods from system:
- 从系统卸载 Cocoapods:
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods
There is a complete tutorial for removing pods from your Xcode project on stackoverflow. You can check on this following link for more info.
在 stackoverflow 上有一个完整的教程,用于从 Xcode 项目中删除 pod。您可以查看以下链接以获取更多信息。
How to remove CocoaPods from a project?
Thanks
谢谢
Hope this helped.
希望这有帮助。
回答by Mr.Javed Multani
Simple Steps to installed pod file:
安装pod文件的简单步骤:
Open terminal 2.Command on terminal: sudo gem install cocoapods
set your project path on terminal.
command : pod init
go to pod file of your project and adding pod which you want to install
added in pod file : pod 'AFNetworking', '~> 3.0
Command : Pod install
Close project of Xcode
open your Project from terminals
Command : open PodDemos.xcworkspace
在终端打开终端 2.Command:sudo gem install cocoapods
在终端上设置您的项目路径。
命令:pod init
转到项目的 pod 文件并添加要安装的 pod
在 pod 文件中添加:pod 'AFNetworking', '~> 3.0
命令:Pod 安装
关闭 Xcode 项目
从终端打开您的项目
命令:打开 PodDemos.xcworkspace
回答by urvashi bhagat
- Open Terminal
- Type in
sudo gem install cocoapods
if you don't have CocoaPods - Enter
cd /project path
, but replaceproject path
with actual project path - touch podfile
- Use one of the following commands to open the podfile:
open -e podfile
to open in TextEdit oropen -a pod file
to open in Xcode - Set your target and add pod file of GoogleMaps like as:
target 'PROJECT NAME HERE' do pod 'GoogleMaps' end
- Use
pod install
to install dependencies
- 打开终端
- 键入
sudo gem install cocoapods
如果你没有的CocoaPods - Enter
cd /project path
,但替换project path
为实际项目路径 - 触摸 podfile
- 使用以下命令之一打开 podfile:
open -e podfile
在 TextEditopen -a pod file
中打开或 在 Xcode 中打开 - 设置您的目标并添加 GoogleMaps 的 pod 文件,例如:
target 'PROJECT NAME HERE' do pod 'GoogleMaps' end
- 使用
pod install
安装依赖
回答by kakyo
On macOS Mojave with Xcode 10.3, I got scary warnings from the gem
route with or without -n /usr/local/bin
:
在带有 Xcode 10.3 的 macOS Mojave 上gem
,无论是否有路由,我都收到了可怕的警告-n /usr/local/bin
:
xcodeproj's executable "xcodeproj" conflicts with /usr/local/bin/xcodeproj
Overwrite the executable? [yN]
What works for me is still Homebrew, just
对我有用的仍然是 Homebrew,只是
brew install cocoapods
回答by Dhruv Narayan Singh
Cocoapods Installation on macOS High Sierra:
在 macOS High Sierra 上安装 Cocoapods:
Install Homebrew https://brew.sh/
Execute following commands in terminal:
安装 Homebrew https://brew.sh/
在终端中执行以下命令:
sudo gem update --system
sudo gem install activesupport -v 4.2.6 sudo gem install -n /usr/local/bin cocoapods pod setup pod setup --verbose
须藤宝石更新--系统
sudo gem install activesupport -v 4.2.6 sudo gem install -n /usr/local/bin cocoapods pod setup pod setup --verbose
回答by Jogendra.Com
Pod Installation giving error on OS X El Capitan 10.11.2
Pod 安装在OS X El Capitan 10.11.2上出现错误
ERROR: Error installing cocoapods: activesupport requires Ruby version >= 2.2.2.
错误:安装 cocoapods 时出错:activesupport 需要 Ruby 版本 >= 2.2.2。
After getting this error tried this command and install again its work for me.
收到此错误后,尝试使用此命令并再次为我安装它。
sudo gem install activesupport -v 4.2.6
Now try same pod installation command
现在尝试相同的 pod 安装命令
sudo gem install -n /usr/local/bin cocoapods
Hope it'll help to all of us.
希望对我们大家都有帮助。
回答by Badal Shah
Here is All step with image. please follow it properly and i am sure you will not get any error.
这是带图像的所有步骤。请正确遵循它,我相信你不会得到任何错误。
From How to install CocoaPods and setup with your Xcode project.
从如何安装 CocoaPods 并使用 Xcode 项目进行设置。
First of all check you have to install command line
or not.
首先检查您是否必须安装command line
。
You can check this by opening Xcode, navigating the menu to
Xcode > Preferences > Downloads > Components, finding Command Line Tools and select install/update.
您可以通过打开 Xcode,将菜单导航到
Xcode > Preferences > Downloads > Components, finding Command Line Tools and select install/update.
if you haven't find command line tool
then you need to write this command in terminal.
xcode-select --install
如果您还没有找到,command line tool
那么您需要在终端中编写此命令。
xcode-select --install
and click on install
然后点击安装
if you have install command line tool. you need to select your Xcode directory (Sometimes this type of problems created due to different versions of Xcode available) follow this procedure.
如果你有安装命令行工具。您需要选择您的 Xcode 目录(有时由于可用的 Xcode 版本不同而导致此类问题)按照此步骤操作。
Open terminal and run this command:
sudo gem install cocoapods
Enter admin password. This could take a while. After few minutes it will show green message is cocoa pods installed successfully in your mac machine.
If you are getting any error with XCode6 like developer path is missing. First run this command in terminal:
sudo xcode-select -switch /Applications/Xcode6.app (or your XCodeName.app)
Now you can setup Pod with your Xcode project.
打开终端并运行以下命令:
sudo gem install cocoapods
输入管理员密码。这可能需要一段时间。几分钟后,它会显示绿色消息是可可豆荚已成功安装在您的 mac 机器上。
如果您在使用 XCode6 时遇到任何错误,例如缺少开发人员路径。首先在终端中运行此命令:
sudo xcode-select -switch /Applications/Xcode6.app (or your XCodeName.app)
现在您可以使用 Xcode 项目设置 Pod。
and now you have to install pod. follow this procedure.
现在你必须安装 pod。遵循此程序。
1)Open Terminal
2) Change directory to your XCode project root directory (where your ProjectName.xcodeproj file is placed).
3)
$ pod setup
: (Setting up CocoaPods master repo)If successful, it shows : Setup completed(read-only access). So, you setup everything. Now Lets do something which is more visible…Yes ! Lets install libraries in your Xcode project.
1) 打开终端
2) 将目录更改为您的 XCode 项目根目录(放置您的 ProjectName.xcodeproj 文件)。
3)
$ pod setup
:(设置CocoaPods master repo)如果成功,则显示:安装完成(只读访问)。所以,你设置了一切。现在让我们做一些更明显的事情......是的!让我们在您的 Xcode 项目中安装库。
now you have to setup and update library related to pod in your project.
现在你必须在你的项目中设置和更新与 pod 相关的库。
Steps to add-remove-update libraries in pod:
1) Open Terminal
2) Change directory to your XCode project root directory. If your terminal is already running then no need to do this, as you are already at same path.
3)
$ touch pod file
4)
$ open -e podfile
(This should open a blank text file)5) Add your library names in that text file. You can add new names (lib name), remove any name or change the version e.g :
pod 'Facebook-iOS-SDK' pod 'EGOTableViewPullRefresh' pod 'JSONKit' pod ‘MBProgressHUD
NOTE:Use ( control + ” ) button to add single quote at both end of library name. It should be shown as straight vertical line. Without control button it shall be added as curly single quote which will give error while installation of file.
6) Save and close this text file. Now libraries are setup and you have to install/update it
7) Go to your terminal again and run this command:
$ pod install
(to install/update these libraries in pod).You should see output similar to the following:
Updating spec repo `master' Installing Facebook-iOS-SDK Generating support files
在 pod 中添加-删除-更新库的步骤:
1) 打开终端
2) 将目录更改为您的 XCode 项目根目录。如果您的终端已在运行,则无需执行此操作,因为您已在同一路径上。
3)
$ touch pod file
4)
$ open -e podfile
(这应该打开一个空白文本文件)5) 在该文本文件中添加您的库名称。您可以添加新名称(lib 名称)、删除任何名称或更改版本,例如:
pod 'Facebook-iOS-SDK' pod 'EGOTableViewPullRefresh' pod 'JSONKit' pod ‘MBProgressHUD
注意:使用( control + ” )按钮在库名的两端添加单引号。它应该显示为垂直的直线。如果没有控制按钮,它将被添加为卷曲单引号,这将在安装文件时出错。
6) 保存并关闭此文本文件。现在库已设置,您必须安装/更新它
7) 再次进入您的终端并运行以下命令:(
$ pod install
在 pod 中安装/更新这些库)。您应该会看到类似于以下内容的输出:
Updating spec repo `master' Installing Facebook-iOS-SDK Generating support files
Setup completed.
设置完成。
Note:-
笔记:-
If you have followed this whole procedure correctly and step by step , then you can directly fire `pod update` command after selecting `Xcode` and then select your project path. and write your command `pod update`
EDIT :-
编辑 :-
you can also check command line tool here.
您还可以在此处查看命令行工具。