pyてよn日記

一寸先は闇が人生

Macbook Pro M3 Max が届いたので環境構築やる

私用の開発マシンとして注文した Macbook Pro M3 Max が届いた。スペースブラックがかっちょいい。

macOS を使用しての開発はこれからもありそうなので、環境構築の手順を備忘録として残しておく。自宅のネットワークが弱々かつ本記事をまとめながら書いていたので計 8 時間くらいかかった(インストールの待ち時間が半分を占めてる)。

マシンスペック

せっかくマシマシにしたのでスペックを nushell で表示。

~> sys | get host
│ name            │ Darwin                                                         │
│ os_version      │ 14.4                                                           │
│ long_os_version │ MacOS 14.4                                                     │
│ kernel_version  │ 23.4.0                                                         │
│ hostname        │ nukopy-mbp-m3max.local
  • CPU: Apple M3 Max (16 Cores)
~> sys | get cpu                                                                                                                     05/11/2024 08:23:20 PM
╭────┬──────┬──────────────┬──────┬───────────┬──────────────────┬───────────╮
│  # │ name │    brand     │ freq │ cpu_usage │   load_average   │ vendor_id │
├────┼──────┼──────────────┼──────┼───────────┼──────────────────┼───────────┤
│  01    │ Apple M3 Max │ 405614.601.81, 2.31, 2.41 │ Apple     │
│  12    │ Apple M3 Max │ 405612.201.81, 2.31, 2.41 │ Apple     │
│  23    │ Apple M3 Max │ 40562.601.81, 2.31, 2.41 │ Apple     │
│  34    │ Apple M3 Max │ 40565.001.81, 2.31, 2.41 │ Apple     │
│  45    │ Apple M3 Max │ 40562.401.81, 2.31, 2.41 │ Apple     │
│  56    │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│  67    │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│  78    │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│  89    │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│  910   │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│ 1011   │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│ 1112   │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│ 1213   │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│ 1314   │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│ 1415   │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
│ 1516   │ Apple M3 Max │ 40560.001.81, 2.31, 2.41 │ Apple     │
╰────┴──────┴──────────────┴──────┴───────────┴──────────────────┴───────────╯
  • メモリ: 128 GiB
~> sys | get mem                                                                                                                     05/11/2024 08:24:27 PM
╭────────────┬───────────╮
│ total      │ 128.0 GiB │
│ free       │ 75.9 GiB  │
│ used       │ 34.0 GiB  │
│ available  │ 110.1 GiB │
│ swap total │ 0 B       │
│ swap free  │ 0 B       │
│ swap used  │ 0 B       │
╰────────────┴───────────╯
  • ストレージ: 4 TiB
~> sys | get disks                                                                                                                 1 05/11/2024 08:26:06 PM
╭───┬──────────────┬──────┬──────────────────────┬─────────┬─────────┬───────────┬──────╮
│ # │    device    │ type │        mount         │  total  │  free   │ removable │ kind │
├───┼──────────────┼──────┼──────────────────────┼─────────┼─────────┼───────────┼──────┤
│ 0 │ Macintosh HD │ apfs │ /                    │ 3.6 TiB │ 3.6 TiB │ false     │ SSD  │
│ 1 │ Macintosh HD │ apfs │ /System/Volumes/Data │ 3.6 TiB │ 3.6 TiB │ false     │ SSD  │
╰───┴──────────────┴──────┴──────────────────────┴─────────┴─────────┴───────────┴──────╯

準備

  • Apple ID の 2 段階認証用の iPhone 端末
  • 各種サービスの 2 段階認証用のアプリ(Authy、GitHubGmail など)をインストールした iPhone 端末

手順

初期設定ウィザード

  • システム言語:English
  • Accesssibility:Not Now
  • リージョン:Japan
  • Migration Assistant:Now Now
  • Wi-Fi
    • SSID:xxxx
    • Password:xxxx
  • Apple ID:
    • Apple ID:xxxx
    • Password:xxxx
  • Computer Account
    • Full name: xxxx
    • Account name: nukopy
    • Password: xxxx

Command Line Tools for XcodeXcode をインストール

Homebrew や他のソフトウェアをビルドするときに大体必要になる。

xcode-select -—install

App Store から Xcode をインストールする。

Xcode

Xcode

  • Apple
  • 開発ツール
  • 無料
apps.apple.com

Homebrew をインストール

brew.sh

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

初期設定に最低限必要なアプリケーションのインストール

まずは諸々設定するのに必要なパスワードマネージャとブラウザをインストールする。

# PATH を一時的に通す
export PATH="/opt/homebrew/bin:$PATH"
brew install --cask 1password google-chrome spotify

brew に PATH を通す設定を永続化するのは、GitHub 上の dotfiles リポジトリを使って zsh の設定をするときなので一旦後回し。

1Password の設定

Launchpad に追加された 1Password を起動し、ログインする

Google Chrome の設定

  1. Launchpad に追加された Google Chrome を起動
  2. Google Chrome をデフォルトブラウザに設定
  3. 1Password を使用して、必要な Google アカウントへログインする。2 段階認証は手元の iPhoneGmail アプリで行う。
  4. メインで使用している Google アカウントの拡張機能の Sync を on にする

Spotify の設定

(作業中に音楽をかけたいのでここも早急に設定する)

  1. Launchpad に追加された Spotify を起動
  2. Google アカウントで Spotify へログイン

(以降 Launchpad は省略)

マウスの設定

MX Ergo の設定

MX Ergo の初期設定を行うため、まずは下記公式 HP からインストーラをダウンロードし、Logi Options+ をインストールする。

www.logitech.com

  1. MX Ergo をペアリングモードにする
  2. System Settings > Bluetooth > Nearby Devices で MX Ergo の Connect をクリック
  3. MBP と MX Ergo のペアリング Done
  4. Logi Options+ を起動
    • System Settings にて、アクセシビリティ等の各種 OS の機能へのアクセスを許可する必要がある
  5. Logi Options+ でマウスの設定を行う

マウスの設定

  • System Settings > Mouce
    • Tracking Speed: 7 (Fast 側)
    • Natural scrolling: on

トラックパッドの設定

こっちもついでに。

  • System Settings > Trackpad
    • Tracking speed: 7 (Fast 側)
    • Click: medium
    • Tap to click: on(Secondary click が Two Fingers になる)

キーボードの設定

  • System Settings > Keyboard
    • キーリピート設定
      • Key repeat rate: Fast Max(右端)
      • Delay until repeat: Short Max(右端)
    • > Keyboard Shortcuts... ボタン
      • > Input Sources
        • Select the previous input source: ^Space(ctrl + スペースで入力ソースの切り替え)
      • > Modifier Keys
        • Caps ロックを ctrl にする(Emacs のショートカット用)
        • Select keyboard: Apple Internal Keyboard / Trackpad
          • Caps Lock key: ^ Control
        • Select keyboard: HHKB Professional
          • Caps Lock key: ^ Control
    • > Text Input > Input Sources > Edit... ボタン
      • All Input Sources
        • 自動訂正、挿入系の設定
          • Correct spelling automatically: off
          • Capitalize words automatically: off
          • Add period with double-space: off
        • クォート設定
          • Use smart quotes and dashes: off(ダブルクォート、シングルクォートが斜めにならないようにする)
            • For double quotes: "abc"
            • For single quotes: 'abc'
      • Japanese - Romaji
        • Live Conversion: off
        • Correct spelling: off

PC 名の変更

Bonjour(mDNS)で使用されるサーバ名を「英小文字+ハイフン」にしたいので、デフォルトの PC 名から変更する。

  • System Settings > General > About
    • Name: xxx

ネットワーク設定

固定 IP を振る。

  • System Settings > Network
    • Wi-Fi: off
    • Ethernet > Details > TCP/IP
      • Configure IPv4: Using DHCP Manual Address(IP アドレス以外の設定は DHCP サーバから情報取りたい。インターネットに出るための DNS の設定とか。)
      • IP address: 192.168.xxx.xxx(他の端末と被らないように注意)

OS の更新設定

  • System Settings > General > Software Update
    • Automatic Updates: off
    • Beta Updates: off

Touch ID の設定

左右の必要な指の指紋を追加。ロック画面の解除や 1Password のロック解除など。

  • System Settings > Touch ID & Passowrd
    • Touch ID > Add Fingerprint

Apple指紋認証の UI すき

言語、リージョン、日付

  • System Settings > General
    • > Language & Region
      • Preferred Languages:
        • English
        • 日本語
      • Region: Japan
      • Calendar: Japanese
      • First day of week: Monday
    • > Date & Time
      • Set time and date automatically: on
      • Set time zone automatically using your current location: on
      • Time zone: Japan Standard Time (JST)
      • Closest city: Tokyo - Japan

Appearance の設定

  • System Settings > Appearance
    • Appearance: Dark

Control Center の設定

メニュバーに表示するアイテムの設定

  • System Settings > Control Center > Control Center Modules
    • Bluetooth: Show in Menu Bar
    • AirDrop: Show in Menu Bar
    • Stage Manager: Show in Menu Bar
    • Screen Mirroring: Always Show in Menu Bar
    • Display: Don't Show in Menu Bar
    • Sound: Always Show in Menu Bar
    • Menu Bar Only
      • Spotlight: Don't Show in Menu Bar

Dock の設定

  • System Settings > Desktop & Dock
    • Size: 小さくする(Dock のアイコンサイズをデフォルトより小さくする)
    • Magnification: インタラクションが発生する程度に設定する(デフォルトはオフになっている)
    • Automatically hide and show the Dock: on

ディスプレイの設定

4K ディスプレイだけ文字の大きさの調節が必要なので設定を行う。

  • System Settings > Displays
    • DeLL U3223QE
      • Use as: Extended display
      • 解像度: 2560 x 1440

Finder の設定

Finder の Settings から設定変更

  • Finder > Settings...
    • > General
      • Show these items on the desktop:
        • ✅ Hard disks
        • ✅ Connected servers
      • New Finder windows show:
        • nukopy(Finder のウィンドウを新規に起動するとき、ホームディレクト/Users/nukopy を表示する)
      • ✅ Open finders in tabs instead of new windows
    • > Sidebar
      • Locations:
        • ✅ nukopy-mbp-m3max
  • > Advanced
    • ✅ Show all filename extensions(拡張子の表示)

CLI からファイルシステム周りの設定を行う

  • Finder のウィンドウのトップバーにフルパスを表示する
defaults write com.apple.finder _FXShowPosixPathInTitle -boolean true
killall Finder
  • 隠しファイルを常に表示する(.git などの dotfiles など)
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
  • スクショの保存先の変更
    • 以下のコマンドを実行したらショートカット cmd + shift + 5 を実行し、~/Desktop/screenshots にスクショが保存されるか確認する
mkdir ~/Desktop/screenshots  # ディレクトリを作成しないとデスクトップに直接スクショが吐かれてしまうので必須
defaults write com.apple.screencapture location ~/Desktop/screenshots
killall SystemUIServer

開発環境の構築

ここからがメイン

X(Twitter)へログイン

twitter.com

GitHub へログイン

github.com

開発ツールのインストール

まずは最低限

brew install make gh eza
brew install --cask alacritty

GitHub CLI の設定

gh auth login コマンドを用いて、Web ブラウザで GitHub へログインする。

gh auth login
# ? What account do you want to log into? GitHub.com
# ? What is your preferred protocol for Git operations on this host? SSH
# ? Generate a new SSH key to add to your GitHub account? Yes
# ? Enter a passphrase for your new SSH key (Optional): 
# ? Title for your SSH key: GitHub CLI
# ? How would you like to authenticate GitHub CLI? Login with a web browser

参考:俺たちはもう GitHub のために ssh-keygen しなくていい

zenn.dev

dotfiles の設定

ひとまず開発用のディレクトリを作っておく。

cd ~
mkdir Projects

dotfiles リポジトリを clone

github.com

cd Projects
gh repo clone nukopy/dotfiles

ブートストラップスクリプトを実行する

cd dotfiles
bash bootstrap.bash 

出力

--------------------------------------------------------------------------------
                                                                                
                 888          888     .d888 d8b 888                             
                 888          888    d88P"  Y8P 888                             
                 888          888    888        888                             
             .d88888  .d88b.  888888 888888 888 888  .d88b.  .d8888b            
            d88" 888 d88""88b 888    888    888 888 d8P  Y8b 88K                
            888  888 888  888 888    888    888 888 88888888 "Y8888b.           
            Y88b 888 Y88..88P Y88b.  888    888 888 Y8b.          X88           
             "Y88888  "Y88P"   "Y888 888    888 888  "Y8888   88888P"           
                                                                                
                        fast environmental construction                         
                                                                                
                          github.com/nukopy/dotfiles                            
                                                                                
--------------------------------------------------------------------------------

========== System Info ==========
Hostname: nukopy-mbp-m3max.local
Hardware:
  CPU: Apple M3 Max
  RAM: 128 GB
  Disk: 3.6Ti
OS:
  Version: macOS 14.4 23E214
  Kernel: Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:54 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6031

========== Make symlinks ==========
Creating symlinks to home directory...
HOME: /Users/nukopy
DOTDIR: /Users/nukopy/Projects/dotfiles
+ ln -sf /Users/nukopy/Projects/dotfiles/gitconfig/.gitconfig /Users/nukopy/.gitconfig
+ ln -sf /Users/nukopy/Projects/dotfiles/gitconfig/.gitignore_global /Users/nukopy/.gitignore_global
+ ln -sf /Users/nukopy/Projects/dotfiles/.zshenv.home /Users/nukopy/.zshenv
+ ln -sf /Users/nukopy/Projects/dotfiles/latex/.latexmkrc /Users/nukopy/.latexmkrc
+ ln -sf /Users/nukopy/Projects/dotfiles/karabiner /Users/nukopy/.config/karabiner
+ ln -sf /Users/nukopy/Projects/dotfiles/direnv/.direnvrc /Users/nukopy/.direnvrc
+ ln -sf /Users/nukopy/Projects/dotfiles/alacritty/alacritty.yml /Users/nukopy/.config/alacritty/alacritty.yml
+ ln -sf /Users/nukopy/Projects/dotfiles/starship/starship.toml /Users/nukopy/.config/starship.toml
+ ln -sf /Users/nukopy/Projects/dotfiles/spacemacs/.spacemacs /Users/nukopy/.spacemacs
+ ln -sf /Users/nukopy/Projects/dotfiles/homebrew/Brewfile /Users/nukopy/.Brewfile
+ set +ex
Creating symlinks for Xcode settings...
+ cp /Users/nukopy/Library/Developer/Xcode/UserData/IDETemplateMacros.plist /Users/nukopy/Library/Developer/Xcode/UserData/IDETemplateMacros.plist.bk
cp: /Users/nukopy/Library/Developer/Xcode/UserData/IDETemplateMacros.plist: No such file or directory
+ cp -r /Users/nukopy/Library/Developer/Xcode/UserData/KeyBindings /Users/nukopy/Library/Developer/Xcode/UserData/KeyBindings.bk
+ rm -rf /Users/nukopy/Library/Developer/Xcode/UserData/KeyBindings
+ ln -sf /Users/nukopy/Projects/dotfiles/xcode/UserData/IDETemplateMacros.plist /Users/nukopy/Library/Developer/Xcode/UserData/IDETemplateMacros.plist
+ ln -sf /Users/nukopy/Projects/dotfiles/xcode/UserData/IDETextMacros.plist /Users/nukopy/Library/Developer/Xcode/UserData/IDETextMacros.plist
+ ln -sf /Users/nukopy/Projects/dotfiles/xcode/UserData/KeyBindings /Users/nukopy/Library/Developer/Xcode/UserData/KeyBindings
+ set +ex
Done!

Please restart your shell, "exec $SHELL -l".

Brewfile を dotfiles リポジトリで管理してはいるけど結局開発途中でいらなくなったり、使わなくなったりするパッケージも結構あるので Brewfile は使わない。

各言語処理系のインストール

Rust with rustup

rustup のインストール

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

www.rust-lang.org

インストールできたか確認

rustc --version
# rustc 1.78.0 (9b00956e5 2024-04-29)

ツールのインストール

cargo install cargo-watch
Deno

Homebrew でインストール

brew install deno

docs.deno.com

インストールできたか確認

deno --version
# deno 1.43.1 (release, aarch64-apple-darwin)
# v8 12.4.254.12
# typescript 5.4.3
Go

Homebrew でインストール

brew install go

インストールできたか確認

go version
# go version go1.22.3 darwin/arm64

複数バージョンのツールチェインを混在させる方法は公式から提供されている。goenv は使う必要がない。以下を参照。

参考:Goでは○○envが不要になった理由(バージョンアップを怠ると損する理由)

tenntenn.dev

go.dev

Python with Rye

グローバルで使用する Python は公式のインストーラで、プロジェクトごとの Python は Rye でインストールする(実際に開発で使うのは Rye)。

  • Python のインストール

www.python.org

  • Rye のインストール
brew install rye

インストールできたか確認

python3 --version
# Python 3.12.3

pip3 --version
# pip 24.0 from /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip (python 3.12)

rye --version
# rye 0.33.0
# commit: 0.33.0 (2024-04-24)
# platform: macos (aarch64)
# self-python: not bootstrapped (target: cpython@3.12)
# symlink support: true
# uv enabled: false

参考:久しぶりのPython環境をRyeで整える

zenn.dev

Node.js with asdf

asdf のインストール

brew install coreutils curl

# "We highly recommend using the official git method." と書かれていたので git を使うやり方でインストール
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
. "$HOME/.asdf/asdf.sh"

asdf-vm.com

asdf がインストールできたか確認

asdf --version
# v0.14.0-ccdd47d

asdf の Node.js 用のプラグインをインストール

# install plugin dependencies
brew install gpg gawk

# install the plugin
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

Node.js をインストール(LTS の v22.x が asdf のインストール可能リストになかったので、ひとまず v20.x をインストール)

nodejs.org

# インストール可能なバージョン一覧
asdf list all nodejs
# ...
# 20.13.1
# ...

# インストール
asdf install nodejs 20.13.1

Node.js がインストールできたか確認

node --version              
# No version is set for command node
# Consider adding one of the following versions in your config file at 
# nodejs 20.13.1

# グローバルの Node.js を設定する
asdf global nodejs 20.13.1

# Node.js のバージョンを表示
node --version            
# v20.13.1

asdf-vm.com

エディタ、IDE の設定

フォントのインストール

フォントのインストール

brew tap homebrew/cask-fonts
brew install --cask \
  font-hack-nerd-font \
  font-fira-code \
  font-noto-sans-gothic
エディタ、IDE のインストール
brew install --cask visual-studio-code jetbrains-toolbox cursor
Visual Studio Code の設定
  1. 起動する
  2. エディタ左下のユーザアイコンをクリック > Backup and Sync Settings > GitHub でログインする。ブラウザでログイン → VScode に制御が戻る。
  3. ログイン Done
  4. 設定の同期が始まる(拡張やキーボードショートカットなど)
  5. エディタでショートカットが使えてれば大体 OK
JetBrains 系 IDE の設定

JetBrains Toolbox 経由で各種 IDE をインストールする。時間かかるのでひとまず IntelliJ IDEA のみ。

  • インストールする IDE
    • IntelliJ IDEA Ultimate
    • (RustRover)
    • (GoLand)
    • (DataGrip)
    • (Rider)
    • (CLion)

  1. IntelliJ IDEA を起動
  2. ライセンスのアクティベート
  3. 設定の同期:IntelliJ IDEA > Settings > Settings Sync
  4. 設定の同期、Plugins などのインストールが走る
  5. GitHub Copilot for IntelliJ IDEA のアクティベート
  6. エディタでショートカットが使えてれば大体 OK
Cursor の設定
  1. VSCode の設定を同期
  2. GitHub アカウントでログイン → ブラウザ → エディタに制御が戻る
  3. エディタでショートカットが使えてれば VSCode の設定の同期ができてる

cursor.sh

Docker Desktop for Mac のインストール

公式のインストーラをダウンロード

docs.docker.com

Rosetta 2 のインストール

softwareupdate --install-rosetta

起動する → Docker Hub にサインインする

CLI でサインイン

docker login
# Authenticating with existing credentials...
# Login Succeeded

試しに Nginx の Docker image を pull してコンテナを起動してみる

# pull
docker pull nginx:latest

# pull
docker run --rm -it -p 8080:80 nginx:latest

ブラウザで http://localhost:8080 にアクセスすると以下が表示された。Docker のセットアップは完了。

残りの開発ツールのインストール

brew install \
  tree \
  pstree \
  clang-format \
  protobuf \
  lazydocker \
  curl \
  wget \
  grpcurl \
  jq \
  jnv \
  ffmpeg \
  direnv \
  htop \
  nats-server \
  # rabbitmq \
  sqlc \
  qemu \
  nushell \
  starship \
  awscli \
  google-cloud-sdk

# cask
brew install --cask \
  arduino-ide \
  blender \
  deepl \
  discord \
  fig \
  figma \
  firefox \
  flutter \
  gimp \
  microsoft-edge \
  miro \
  obs \
  obsidian \
  protokol \
  kodelife \
  sf-symbols \
  touchdesigner \
  wireshark \
  zoom \
  zulip

Tailscale クライアントを App Store でインストール後ブラウザ経由でアクティベート

tailscale.com

その他のツールのインストール

brew install --cask \
  clipy \
  monitorcontrol \
  rectangle \
  hiddenbar

clipy の設定

  1. 以前使っていた MBP から XML 形式の設定を Export → AirDrop で共有
  2. 現在使っている MBP で Clipy を開き XML を Import

rectangle の設定

おすすめ設定を選択。ctrl + alt + 矢印キーでフォーカスしているウィンドウの位置、大きさが制御できれば OK。

終わりに

お財布に無理を言って人生で初めて 3 桁万円のお買い物をした(MBP M3 Max 本体 + Apple Care の価格)。 高いお金をかけてスペックマシマシにしたので 4 年以上は使えて欲しい。精進する。