MacBook Pro M1 開箱使用紀錄

👀 9 min read 👀

大家好,我是 Cindy,勇者我最近換了 MacBook Pro M1,想把各種安裝過程記錄下來,也希望可以幫助到大家 :)
不過因為是紀錄可能蠻瑣碎的,有需要的人可以直接跳到自己有需要的段落歐,另外如果之後還有遇到其他問題,這篇應該會持續更新。

目錄

安裝各種 APP

iTerm

m1 的 shell 預設是 zsh

安裝 for m1(arm) 的 homebrew

  1. 在 terminal 執行以下指令
    1
    2
    # 系統會將 homebrew 安裝在 /opt/homebrew
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. 在 terminal 執行以下指令,確認 path
    1
    2
    3
    echo $path

    # /usr/local/bin ...
  3. 在 terminal 執行以下指令,打開 .zshrc
    1
    open ~/.zshrc
    • 將以下新增至 .zshrc 檔案中
      1
      2
      3
      4
      5
      6
      # 由於第 2 步驟已經確定此路徑不在 path 中,
      # 故需要加入此路徑才能讓用 brew 指令安裝的套件在執行的時候被找到
      export PATH=/opt/homebrew/bin:$PATH

      # 讓 brew 的指令會去找安裝在 /opt/homebrew/ 的 homebrew
      alias brew='/opt/homebrew/bin/brew'
  4. 確認有成功安裝
    • command+T 重開一個分頁,或在 terminal 執行以下指令
      1
      2
      3
      source ~/.zshrc
      # or
      exec $SHELL
      • 由於要確認 terminal 有吃到 .zshrc 最新的設定,所以需要做上面步驟
        • 最後我還是都直接重開一個分頁,因為重新執行的時候,如果 path 改來改去,曾經有新增的 path 會一直加上去
    • 在 terminal 執行 brew config 可正常執行
      1
      2
      3
      4
      5
      6
      brew config

      ## ...
      ## macOS: 11.4-arm64
      ## ...
      ## Rosetta 2: false
    • 確認 path 有被修改到,在 terminal 執行以下指令
      1
      2
      3
      echo $path

      # /opt/homebrew/bin /usr/local/bin ...

安裝 for intel(x86) 的 homebrew

由於舊的套件可能不支援 m1,所以另外透過 Rosetta 安裝一個 for intel 版本的 homebrew

  1. 在 terminal 執行以下指令
    1
    2
    # 系統會將 homebrew 安裝在 /usr/local
    arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. 在 terminal 執行以下指令,打開 .zshrc
    1
    open ~/.zshrc
    • 將以下新增至 .zshrc 檔案中
      1
      2
      # 讓 ibrew 的指令會去找安裝在 /usr/local/ 的 homebrew
      alias ibrew='arch -x86_64 /usr/local/bin/brew'
  3. 確認有成功安裝
    • 在 terminal 執行 ibrew config 可正常執行
      1
      2
      3
      4
      5
      6
      ibrew config

      ## ...
      ## macOS: 11.4-x86_64
      ## ...
      ## Rosetta 2: true

安裝 oh my zsh

  1. 在 terminal 執行以下指令

    1
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

    完成的話就安裝好囉

  2. 安裝字型

    • 在 terminal 執行以下指令
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      # 先執行這行,才能用 homebrew 安裝字型。
      # 曾經執行過的人可以跳過這個指令
      # 舊指令:brew tap caskroom/fonts
      brew tap homebrew/cask-fonts

      # 看有哪些 nerd 字型可以下載
      brew search nerd

      # 挑一個字型來安裝
      brew install font-go-mono-nerd-font
    • 修改字型
      • 在 terminal 的 Preferences -> Profiles -> Text 修改(如圖圈起來的地方),選剛剛下載的字型
  3. 在 terminal 執行以下指令,安裝主題套件 powerlevel9k

    1
    git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
  4. 編輯 ~/.zshrc 檔案 (大家可以依照自己的喜好設定)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ZSH_THEME="powerlevel9k/powerlevel9k"

    POWERLEVEL9K_MODE='nerdfont-complete'

    DEFAULT_USER="cindy"

    # command line 左邊想顯示的內容
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir dir_writable vcs vi_mode)

    # command line 右邊想顯示的內容
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status ram load time)
  5. 修改顏色

    • 在 terminal 的 Preferences > Profiles > Colors (如圖),選自己想要的顏色
  6. 安裝 zsh-autosuggestionszsh-syntax-highlighting 套件

    • 在 terminal 執行以下指令
      1
      2
      git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
      git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
    • 修改 .zshrc 檔案
      1
      plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
  7. 成果

參考資料:

設定 Sublime Text

  1. 在 sublime 的 Preferences -> Settings 打開後右邊檔案加入個人設定

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    {
    "auto_complete": true,
    "caret_extra_bottom": 0,
    "caret_extra_top": 0,
    "caret_extra_width": 2,
    "copy_with_empty_selection": true,
    "ensure_newline_at_eof_on_save": true,
    "font_face": "Roboto Mono for Powerline",
    "font_size": 19,
    "highlight_line": true,
    "ignored_packages": ["Vintage"],
    "index_files": true,
    "overlay_scroll_bars": "enabled",
    "rulers": [79],
    "save_on_focus_lost": true,
    "spell_check": true,
    "tab_size": 2,
    "theme": "auto",
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": "all",
    "color_scheme": "Packages/Color Scheme - Default/Monokai.sublime-color-scheme",
    }
  2. 安裝套件

  3. 在 terminal 執行以下指令,設定可直接在 terminal 用 subl 開啟 sublime

    1
    2
    # 建立軟連結
    ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

安裝 rbenv

ruby 管理工具

  1. 確認 rbenv 從 homebrew 安裝是否有支援 m1

  2. 在 terminal 執行以下指令

    1
    brew install rbenv
  3. 在 terminal 執行以下指令,會顯示要設定在 .zshrc 檔案中的指令

    1
    rbenv init
  4. 編輯 .zshrc 檔案,想知道詳細做了什麼可以參考 How rbenv hooks into your shell,由於每次打開 terminal 都會執行一次 ~/.zshrc 所以可以將 rbenv 的路徑放到 path 中 (Understanding Shims)

    1
    eval "$(rbenv init -)"
  5. 在 terminal 開新分頁,執行以下指令確認有安裝成功

    1
    2
    3
    4
    curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash

    # 確認 rbenv 有被加到 path 中
    echo $path
  6. 在 terminal 執行以下指令,安裝 ruby 3.0.1

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # 列出最後穩定版本
    rbenv install -l

    # 列出所有 local 版本
    rbenv install -L

    # 安裝 3.0.1
    rbenv install 3.0.1

    # 確認已安裝的 ruby 版本
    rbenv versions

    參考資料: rbenv: How to switch to another Ruby version (temporarily, per project, or globally)

  7. 在 terminal 執行以下指令,安裝 ruby 2.6.7

    1
    CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.7

    遇到 Installing 2.6.7 on macOS 11.2.3 fails with implicit-function-declaration error 問題

  8. 在 terminal 執行以下指令,安裝 ruby 2.3.7
    舊版的 ruby 在 arm64 下超級難裝,會遇到 openssl 要去抓舊版 1.0 但是已經抓不到的情況,還會遇到 ffi 的問題,所以這邊勇者做了各種嘗試 (不確定是否有可以省略的步驟),最後終於成功了!
    註:

    • 聽同事說他是完全在 x86_64 的環境下安裝成功的,所以我做了以下步驟
    • 為了防止 arm64 版本安裝的套件被讀取到,所以我把 export PATH=/opt/homebrew/bin:$PATH 暫時先 hide 起來
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      ibrew install openssl@1.0
      ibrew install readline

      # 改用 x86_64 版的 homebrew 重新安裝 rbenv
      brew uninstall rbenv
      ibrew install rbenv

      brew uninstall ruby-build
      ibrew reinstall ruby-build

      export LDFLAGS="-L/usr/local/opt/openssl@1.0/lib"
      export CPPFLAGS="-I/usr/local/opt/openssl@1.0/include"

      # RUBY_CFLAGS="-Wno-error=implicit-function-declaration" 解決 ffi 的問題
      # CONFIGURE_OPTS="--with-openssl-dir=$(ibrew --prefix openssl@1.0)" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(ibrew --prefix openssl@1.0)" 解決找不到 openssl 的問題
      RUBY_CFLAGS="-Wno-error=implicit-function-declaration" CONFIGURE_OPTS="--with-openssl-dir=$(ibrew --prefix openssl@1.0)" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(ibrew --prefix openssl@1.0)" arch -x86_64 rbenv install 2.3.7
  9. 安裝 bundler (如果沒有的話)

    1
    gem install bundler

安裝 nvm

nvm 是管理 Node.js 的套件,類似 Ruby 的 rbenv 或 rvm

  1. 輸入以下指令進行安裝
    1
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  2. 將以下新增至 .zshrc 檔案中
    1
    2
    3
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
  3. 安裝 Node.js
    安裝 v15 的時候會出現跑很久的情況,但等待之後會成功安裝,可參考這裡
    1
    2
    3
    4
    nvm install v16
    nvm install v15

    nvm list

安裝 yarn

1
brew install yarn

安裝 MySQL & PostgreSQL & Redis

直接用 homebrew 裝就可以囉,經查詢 MySQL 5.7 和 PostgreSQL 9.5 以上目前都有支援 Apple Silicon 了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
brew install mysql@5.7
brew install mysql

brew services start mysql@5.7
brew services stop mysql@5.7

brew install postgresql@9.6
brew install postgresql

brew services start postgresql@9.6
brew services stop postgresql@9.6

brew install redis
brew services start redis
redis-cli

brew services list

安裝 rails

1
gem install rails

安裝其他套件