Cocoapods 安装教程 pod command not found

第一步,首先要检查Mac是否安装了rvm。打开终端,输入指令

rvm -v

发现没有安装则开始安装

step1 :安装rvm

curl -L get.rvm.io | bash -s stable

没有报错即安装成功(有Thank you...)。

Step 2: 指定源

source ~/.rvm/scripts/rvm

Step 3: 查看版本确认是否安装成功

rvm -v

Step 4: 列出所有指定源里的ruby版本

rvm list known

根据输出发现最新版本就是3.0.0

第二步,用rvm安装ruby环境

注意,当ruby版本低于2.7时,安装cocoapods会报错,可通过指令 ruby -v检查当前版本。

版本过低时,报错信息如:

ERROR:  Error installing cocoapods:
	The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.3. Try installing it with `gem install activesupport -v 6.1.7.3` and then running the current command again
	activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
yangdj@MrdeMac-mini ~ % rvm install 3.0.0
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/12.6/x86_64/ruby-3.0.0.tar.bz2
Checking requirements for osx.
About to install Homebrew in the default location `/usr/local`.

It is possible to select a custom location, however it is not recommended and some things might not work.
You should do it only if you do not have write rights to `/usr/local`.

Press ENTER to install Homebrew in the default location `/usr/local`
or type a custom path (needs to be writable for the current user)
: 
curl: (22) The requested URL returned error: 404
Something went wrong during Homebrew installation,
can not find 'brew' command, please report a bug: https://github.com/rvm/rvm/issues
Requirements installation failed with status: 1.

升级ruby到3.0.0

好吧,老实升级,输入指令:

rvm install 3.0.0

然后根据提示按“enter”键。可能会升级失败,我这里因为brew没有而升级失败了,错误信息:

Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/12.6/x86_64/ruby-3.0.0.tar.bz2
Checking requirements for osx.
About to install Homebrew in the default location `/usr/local`.

It is possible to select a custom location, however it is not recommended and some things might not work.
You should do it only if you do not have write rights to `/usr/local`.

Press ENTER to install Homebrew in the default location `/usr/local`
or type a custom path (needs to be writable for the current user)
: 
curl: (22) The requested URL returned error: 404
Something went wrong during Homebrew installation,
can not find 'brew' command, please report a bug: https://github.com/rvm/rvm/issues
Requirements installation failed with status: 1.

安装brew

输入命令:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

1.运行命令,输入序列号时 直接回车

2."是否现在开始执行脚本?" 输入大写字母:Y

3.输入mac密码,运行脚本

4.出现提示需要git,直接根据提示安装,安装完成后,重新执行脚本

5.安装成功

继续回去升级ruby

rvm install 3.0.0

继续报错:

Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, libksba, readline, zlib, openssl@1.1 - please wait
There were package installation errors, make sure to read the log.

Try `brew tap --repair` and make sure `brew doctor` looks reasonable.

Check Homebrew requirements https://docs.brew.sh/Installation
Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config coreutils libyaml libksba readline zlib openssl@1.1',
please read /Users/xxx/.rvm/log/1683789834_ruby-3.0.0/package_install_autoconf_automake_libtool_pkg-config_coreutils_libyaml_libksba_readline_zlib_openssl@1.1.log
Requirements installation failed with status: 1.

查看该错误日志,得到:

...
==> Fetching openssl@1.1
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/openssl%401.1-1.1.1t.monterey.bottle.tar.gz
==> Installing dependencies for autoconf: m4
==> Installing autoconf dependency: m4
fatal: not in a git directory
Error: Command failed with exit 128: git
+requirements_osx_brew_libs_install:4> typeset 'ret=1'
+requirements_osx_brew_libs_install:6> requirements_osx_brew_libs_error installation
+requirements_osx_brew_libs_error:2> rvm_warn $'There were package installation errors, make sure to read the log.\n\nTry `brew tap --repair` and make sure `brew doctor` looks reasonable.\n\nCheck Homebrew requirements https://docs.brew.sh/Installation'
+rvm_warn:2> rvm_pretty_print stderr
+rvm_pretty_print:2> case auto (0|no)
+rvm_pretty_print:2> case auto (1|auto)
+rvm_pretty_print:8> case xterm-256color (dumb|unknown)
+rvm_pretty_print:12> case stderr (stdout)
+rvm_pretty_print:12> case stderr (stderr)
+rvm_pretty_print:14> [[ -t 2 ]]
+rvm_pretty_print:14> return 1
+rvm_warn:4> printf %b $'There were package installation errors, make sure to read the log.\n\nTry `brew tap --repair` and make sure `brew doctor` looks reasonable.\n\nCheck Homebrew requirements https://docs.brew.sh/Installation\\n'
+requirements_osx_brew_libs_install:8> return 1

查资料发现是brew有问题,输入:brew -v,果然有错:

Homebrew 4.0.17-63-g32f2258
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

	git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:

	git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

实际就是homebrew的根目录没有信任Homebrew/homebrew-core (no Git repository)和Homebrew/homebrew-cask (no Git repository),怎么解决以上的问题。
直接按照提示的运行这两个命令行即可

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

又又又继续回去升级ruby

rvm install 3.0.0

又又又报错了:

Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/12.6/x86_64/ruby-3.0.0.tar.bz2
Checking requirements for osx.
Installing requirements for osx.
Updating system - please wait
Failed to update Homebrew, follow instructions at

    https://docs.brew.sh/Common-Issues

and make sure `brew update` works before continuing.
Error running 'requirements_osx_brew_update_system ruby-3.0.0',
please read /Users/xxx/.rvm/log/1683790553_ruby-3.0.0/update_system.log
Requirements installation failed with status: 1.

好像在说请确保命令brew update是正常的,执行下,发现一个警告:

yangdj@MrdeMac-mini ~ % brew update
Warning: No remote 'origin' in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Already up-to-date.

好像在说没有这个仓库,添加进去:

git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services

注意:添加的目录是错误提示里的,这样不要原样复制(我就是原样复制,搞半天发现拷贝的人家的目录-_-||)

叕叕继续回去升级ruby

rvm install 3.0.0

又报错了:

Error running ' CFLAGS=-O3 -I/usr/local/opt/libyaml/include -I/usr/local/opt/libksba/include -I/usr/local/opt/readline/include -I/usr/local/opt/zlib/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/libksba/include -I/usr/local/opt/readline/include -I/usr/local/opt/zlib/include -I/usr/local/opt/openssl@1.1/include LDFLAGS=-L/usr/local/opt/libyaml/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/openssl@1.1/lib ./configure --prefix=/Users/yangdj/.rvm/rubies/ruby-3.0.0 --disable-install-doc --enable-shared',
please read /Users/yangdj/.rvm/log/1683791195_ruby-3.0.0/configure.log
There has been an error while running configure. Halting the installation.

看日志内容:__rvm_log_dotted:23: permission denied:。
网上找到解决方案,执行命令:

rvm install ruby-3.0.0 --with-openssl-dir='brew --prefix openssl'

安装完成,输入指令:rvm list

# 输出
=* ruby-3.0.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

终于安装成功了,泪目( Ĭ ^ Ĭ )~
如果发现有多个版本,可以设置默认版本。
输入rvm list,可以查看本地已经安装过的ruby版本,有正在使用的版本、默认版本和正在使用且为默认的版本三个选项。
输入rvm use 3.0.0,将3.0.0切换current版本,
输入rvm rvm --default use 3.0.0,将3.0.0版本设置为默认且正在使用的版本。

第三步,检查更新RubyGems(Ruby1.9.1 以后的版本自带RubyGems)

RubyGems是一个方便而强大的Ruby程序包管理器,Ruby的第三方插件是用gem方式来管理,非常容易发布和共享,一个简单的命令就可以安装上第三方的扩展库。
建议RubyGems升级到2.6.x以上。
查看RubyGems的版本用指令:gem -v
更新RubyGems的版本指令:gem update --system

第四步,检查ruby源并移除

先是检查ruby源

gem sources -l 

输出:

*** CURRENT SOURCES ***
https://rubygems.org/

然后执行以下命令移除现有源并添加国内源:

gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com 

之所以要添加国内的ruby-china源,是因为taobao源已经停止维护了,所以此处替换的是ruby-china源,且尽量确保只有一个。

第五步,安装CocoaPods(sudo 表示管理员执行指令,需要输入密码的)

注意:
OS X 10.11之前系统的安装cocoapods 指令:

sudo gem install cocoapods

OS X 10.11以后系统的安装cocoapods 指令:

sudo gem install -n /usr/local/bin cocoapods

如果有 gems installed标志着安装成功了。
到这里,cocoapods已经安装成功了!恭喜恭喜!!!
可以愉快的下载pod了

pod install --repo-update
posted @ 2023-05-11 15:57  流失的痕迹  阅读(3142)  评论(1编辑  收藏  举报