---
# System prepended metadata

title: ＭySmartPal - 編譯環境安裝

---

# ＭySmartPal - 編譯環境安裝
* 因使用cocoapod第三方套件需以下安裝步驟

## 查看當前ruby版本

> ruby -v
## 安装RVM
> curl -L get.rvm.io | bash -s stable
>     source ~/.bashrc
>     souce ~/.bash_profile
 
## 目前可裝版本 
> rvm list known
 
## 按裝Homebrew
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

## Homebrew环境变量设置

```
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/Alex/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
```

## 安装rvm

> rvm install 2.7.2
--
or
rvm reinstall ruby-2.7.2


## 再查看一次版本 
> ruby -v
```
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]
```

(2擇1: 2為優)
---
## 安装Cocoapods - 1
M1安装前：
 
> 打開Finder->打開終端應用程序->打開工具程式，找到終端機.app，取得資訊，使用Rosetta打開勾上，然後重啟
 
M1另外需要安装：

> sudo gem install ffi

1查看源$ 
> gem sources -l

2删除源$ 
> sudo gem sources --remove https://rubygems.org/ 

3设置新的源$ 

> sudo gem sources -a https://gems.ruby-china.com/ 

## 安装CocoaPods - 2

先卸载cocoapods乾淨：
> sudo gem uninstall cocoapods

查看cocoapods版本：

> pod --version

不指定版本安装(M1使用這個)：

> sudo gem install -n /usr/local/bin  cocoapods
 
> pod setup

然後進入開發程式專案檔工作目錄
更新第三方套件libray內容
>pod install



---
## 參考資料
[ref1:安裝法1](https://blog.csdn.net/weixin_41448189/article/details/120271066)


[ref2:安裝法2](https://blog.csdn.net/sinat_31177681/article/details/51363495?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-5-51363495.pc_agg_new_rank&utm_term=m1+mac+%E7%94%B5%E8%84%91%E5%AE%89%E8%A3%85cocoapods%E6%98%AF%E5%90%A6%E6%88%90%E5%8A%9F&spm=1000.2123.3001.4430)

[ref3: homebrew安裝失敗時要remove homebrew](https://iter01.com/593703.html)
解決方案：解除安裝重灌 brew
[下載](https://raw.githubusercontent.com/Homebrew/install/master/uninstall)... 並儲存為 uninstall.rb，再執行 ruby uninstall.rb

```
#!/usr/bin/ruby

STDERR.print <<EOS
Warning: The Ruby Homebrew uninstaller is now deprecated and has been rewritten in
Bash. Please migrate to the following command:
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

EOS

Kernel.exec "/bin/bash", "-c", '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"' + ' uninstall ' +  ARGV.join(" ")
```
[refs](https://segmentfault.com/a/1190000037439936)


**以上方法適用macOS 12.4以下

============

macOS 13.0目前要用加這些方式
Install RVM
`curl -sSL https://get.rvm.io | bash`
 
Then install ruby 3.1.1
`rvm install 3.1.1`
 
Install cocoapods
`sudo gem install cocoapods`
 
Then do pod install
`pod install `
# 