• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Mac下安装homeBrew和ruby

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

https://www.jianshu.com/p/39f22e82c97f

https://www.cnblogs.com/yaogengzhu/p/10833285.html

https://www.jianshu.com/p/f5591af6859d

 

关于CocoaPods,是OS X和iOS下的一个第三方类库管理工具,它的好处这里不多说,主要说下如何安装CocoaPods。

CocoaPods的安装需要Ruby环境,Mac系统都自带Ruby,通过下面终端命令查看Ruby版本:
ruby -v

~$ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

CocoaPods支持的Ruby最低版本是2.2.2,如果自己的版本低于2.2.2就需要更新升级Ruby:
sudo gem update --system

更换Ruby镜像

Ruby默认的源地址是国外网络地址,通过下面终端命令查看当前镜像地址:
gem sources -l

~$gem sources -l
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
*** CURRENT SOURCES ***

https://rubygems.org/

首先移除当前镜像
gem sources --remove https://rubygems.org/

~$gem sources --remove https://rubygems.org/
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
https://rubygems.org/ removed from sources

然后添加国内最新Ruby镜像地址
gem sources -a https://gems.ruby-china.com/

~$gem sources -a https://gems.ruby-china.com/
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
https://gems.ruby-china.com/ added to sources

这时候再查看镜像地址就是这样的了

~$gem sources -l
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
*** CURRENT SOURCES ***

https://gems.ruby-china.com/

安装CocoaPods

Ruby环境安装好以后,接下来就是安装CocoaPods,终端输入:
sudo gem install cocoapods

~$sudo gem install cocoapods
Password:
......

Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, nap, fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 33 seconds
28 gems installed

如果终端出现上面的提示,表示安装成功。到这里还剩最后一步,还需执行命令:
pod setup
这一步可能需要耐心等待,需要下载上百M的文件。

~$pod setup
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /Applications/Cocos/tools/ant/bin in PATH, mode 040777
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Enumerating objects: 179, done.        
  remote: Counting objects: 100% (179/179), done.        
  remote: Compressing objects: 100% (135/135), done.        
  remote: Total 2819986 (delta 66), reused 64 (delta 42), pack-reused 2819807        
  Receiving objects: 100% (2819986/2819986), 614.27 MiB | 834.00 KiB/s, done.
  Resolving deltas: 100% (1676501/1676501), done.
  Checking out files: 100% (304760/304760), done.
Setup completed

至此,CocoaPods安装完成!

使用CocoaPods

在使用之前,我们先验证下CocoaPods是否安装成功,搜索一个第三方库。终端输入:
~$pod search AFNetworking
正常情况下,这是会提示Creating search index for spec repo 'master'...等待一会就会出现搜索结果了(也可能需要等待很长时间,大约二十几分钟,不要着急,耐心等待就行?)。

 
屏幕快照

出现上图这个就说明成功了。直接按“Q”键就可以退出。

 


接下来,终端进入iOS项目工程的根目录(就是*.xcodeproj所在的目录),然后创建Podfile文件,终端输入:
~$touch Podfile

这时工程目录下多了一个Podfile文件。


现在我们要接入Admob广告SDK,就可以使用CocosPods的方法,用编辑器打开Podfile文件,并将下面的的代码加到里面:

platform :ios, '8.0'
target 'MyApp' do
pod 'Google-Mobile-Ads-SDK'
end

其中,MyApp应该是你项目中的Target名称。文件保存后,在终端中输入~$pod install

安装成功后,工程目录中会生成一个*.xcworkspace文件。

以后打开工程就打开这个文件,不再使用*.xcodeproj文件。

问题报错

当我们打开*.xcworkspace文件使用Xcode编译时,可能会报这么一个错误:

diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

问题解决参考博客:https://www.jianshu.com/p/5d6e1942dfb1



作者:吃菜小怪兽
链接:https://www.jianshu.com/p/39f22e82c97f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

Homebrew是一个包管理器,用于在Mac上安装一些OSX上没有的UNIX工具(比如wget)。

brew官网

1.安装,打开终端,复制粘贴,大约1分钟左右,下载完成,过程中需要输入密码,其他无需任何操作:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.卸载,有安装就要有卸载,打开终端,复制粘贴:

其实只用把上面安装的install换成uninstall就行了。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

3.Homebrew 怎么使用?常用命令有哪些?

安装软件,如:brew install oclint
卸载软件,如:brew uninstall oclint
搜索软件,如:brew search oclint
更新软件,如:brew upgrade oclint
查看安装列表, 如:brew list
更新Homebrew,如:brew update
使用brew安装wget:
brew install wget
秘籍一:使用wget更新hosts
wget https://raw.githubusercontent.com/racaljk/hosts/master/hosts -qO /tmp/hosts && sudo sh -c 'cat /tmp/hosts > /etc/hosts'

 

 

 

 

 

mac--“-bash: brew: command not found”,怎么解决?

报错

1
-bash: brew: command not found”

执行下面命令,安装HomeBrew

1
ruby -"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

此时报错:

1
2
Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Library/Taps/homebrew/homebrew-core --config core.autocrlf=false --depth=1 -q
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core -q

 

依次执行下面两行命令即可成功解决

1、sudo chown -R apple:staff *

2、brew doctor

命令执行完之后HomeBrew也就安装好了

 

好了,小伙伴们,可以开始你们的操作啦

brew install xxx           安装xxx

brew uninstall xxx       卸载xxx

brew update  xxx         更新xxx

brew doctor                 修复brew

 

python 中文名:蟒蛇,设计者:Guido van Rossum
 
 

 

报错

1
-bash: brew: command not found”

执行下面命令,安装HomeBrew

1
ruby -"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

此时报错:

1
2
Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Library/Taps/homebrew/homebrew-core --config core.autocrlf=false --depth=1 -q
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core -q

 

依次执行下面两行命令即可成功解决

1、sudo chown -R apple:staff *

2、brew doctor

命令执行完之后HomeBrew也就安装好了

 

好了,小伙伴们,可以开始你们的操作啦

brew install xxx           安装xxx

brew uninstall xxx       卸载xxx

brew update  xxx         更新xxx

brew doctor                 修复brew

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
RubyonRails的开发环境配置发布时间:2022-07-18
下一篇:
rubyhttp爬虫中的:body用法问题发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap