0%

Mac 电脑的个人配置

本文记录自己新装电脑后的软件安装和个性化配置,以及之后的维护。

软件安装

App Store

  • 1Password
  • Spark
  • Fantastical
  • Todoist
  • Notability
  • MindNode
  • Drafts
  • Reeder
  • Xcode
  • Sequel Ace
  • Wechat
  • QQ
  • Pages
  • Keynote
  • Numbers
  • WPS Office
  • Apple Developer
  • Swift Playgrounds
  • CloudMounter
  • The Unarchiver
  • Magnet
  • Bear
  • Amphetamine
  • Petrify
  • Cleaner for Xcode
  • quicktype

Homebrew

安装 Homebrew

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

使用 Homebrew 安装软件:

1
$ brew install <name>
  • mysql
  • git
  • sqlite
  • nvm(如果安装多版本 node)
  • node(如果只安装单版本 node)

使用 brew cask 安装应用:

1
$ brew install --cask <name>
  • android-studio
  • google-chrome
  • oracle-jdk
  • openjdk
  • openjdk@8
  • appcleaner
  • iina
  • pdf-expert
  • baidunetdisk
  • imazing
  • picgo
  • db-browser-for-sqlite
  • iterm2
  • postman
  • downie
  • moneywiz
  • fliqlo
  • mweb
  • visual-studio-code
  • github
  • notion
  • dash
  • sketch
  • figma
  • feishu

手动安装

  • SF Symbols
  • ClashX
  • trojan-qt5

配置和维护

需要激活的 App

  • MoneyWiz
  • MWeb
  • Sketch
  • PDF Expert
  • Downie

系统配置

System Preferences

  • General -> SideBar icon size: Small
  • General -> Recent items: 5
  • Desktop & Screen Saver -> Screen Saver: Fliqlo
  • Desktop & Screen Saver -> Start after: 5 Minutes
  • Dock -> Position on screen: Left
  • Dock -> Show recent application in Dock: NO
  • Notifications: 对所有 App 进行配置
  • Accessibility -> Pointer Control -> Trackpad Options -> Enable dragging: three finger drag
  • Security & Privacy -> General -> Requeire passowrd: 5seconds
  • Security & Privacy -> FileVault: Turn On
  • Security & Privacy -> Firewall: Turn On
  • Keyboard -> Text -> Correct spelling automatically: NO
  • Keyboard -> Input Sources: 增加小鹤双拼
  • Trackpad: 打开所有手势
  • Displays -> NightShift: Turn On

Finder

  • General -> New Finder windows show: qiweipeng
  • Tags: 添加到 Favorite Tags
  • SideBar -> Favorites: 仅保留 Applications、Downloads、qiweipeng

Safari

  • 首页 -> Show Frequently Visited: Turn Off
  • General -> Open "safe" files after downloading: No
  • Search -> Search engine: Google
  • Advanced -> Show Develop menu in menu bar: Yes
  • Extensions: 各个插件具体配置

其它

  • FaceTime -> Ringtone: Hillside
  • Message -> Message received sound: Bamboo
  • 所有的系统 App 打开 iCloud 账户同步功能

Homebrew

常用命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ brew list // 安装的软件列表

$ brew install <name> // 安装某个包

$ brew uninstall <name> // 卸载安装的软件

$ brew update // 更新 Homebrew 本身

$ brew outdated 查看过期软件

$ brew upgrade <formula> // 更新指定软件

$ brew pin <formula> 指定某软件保持在当前版本不被更新

$ brew unpin <formula> 取消某软件保持在当前版本

$ brew --cache 查看 Homebrew 缓存目录

// cask 相关

$ brew install --cask <name> // 使用 cask 安装软件

$ brew list --cask // 使用 cask 命令安装的应用列表

$ brew cask uninstall <name> // 卸载使用 cask 命令安装的应用

$ brew cask search <name> // 查找

避免 Homebrew 自动更新:在 ~/.zshrc 文件中写入 export HOMEBREW_NO_AUTO_UPDATE=true

安装 homebrew-cask-upgrade 方便 cask 应用更新:

1
2
3
4
5
$ brew tap buo/cask-upgrade // 安装

$ brew cu -a // 更新所有

$ brew cu <name> -a 更新指定

node

常用命令:

1
2
3
$ npm list // 查看当前目录安装的包

$ npm list -g --depth 0 // 查看本地全局安装过的包

如果需要多版本的 node 则可以通过 brew install nvm 安装 nvm,之后通过 nvm 安装和管理各版本的 node

nvm

安装流程:

1
brew install nvm

.zshrc 中写入:

1
2
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm

安装指定版本:

1
2
// 安装 12.16.3
nvm install v12.16.3

查看:

1
nvm list

如果安装了多个版本,使用如 nvm use v12.16.3 切换到指定版本(重启终端将恢复默认版本),使用如 nvm alias default v12.16.3 设置默认版本。

CocoaPods

安装 CocoaPods

1
$ sudo gem install cocoapods

CocoaPods 版本更新:首先使用 $ sudo gem install cocoapods 安装最新版本,之后看哪些被更新了($ gem list),再将旧版本卸载掉,比如 $ sudo gem uninstall cocoapods-core -v 1.9.1

常用命令:

1
2
3
4
5
pod repo // 查看本地关联了哪些仓库源

pod repo update // 本地仓库更新

pod repo update <name> // 更新指定的仓库

Git

参考个人文章《macOS 下 Git 多账号配置,同时管理多个 SSH Key》配置 SSH Key,主要用在 GitHub。

参考个人文章《如何设置 Git 全局忽略 .DS_Store 文件》配置全局忽略文件。

参考个人文章《记录一些 Git 的命令》对 Git 进行配置,如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 设置全局的用户名和邮箱
$ git config --global user.name "<name>"
$ git config --global user.email "<email address>"

// 让 Git 输出语句显示颜色
$ git config --global color.ui true

// 给常用 Git 命令设置别名,以快捷输入,这个依然是保存在家目录的 .gitconfig 文件中
$ git config --global alias.st status
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.br branch
$ git config --global alias.unstage 'reset HEAD'
$ git config --global alias.last 'log -1'
$ git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

Java

使用 brew 安装 openjdk 后,需要关注(使用 brew info openjdk 查看):

1
2
3
4
5
6
7
8
9
10
11
12
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

If you need to have openjdk first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"

同样,安装 openjdk@8 后,需要关注(使用 brew info openjdk@8 查看):

1
2
3
4
5
6
7
8
9
10
11
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk

openjdk@8 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have openjdk@8 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk@8/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk@8 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@8/include"

(这是直接安装 Oracle JDK 时的配置,OpenJDK 也可以做类似配置,或直接在需要时更改 .zshrc 文件中两个版本的声明顺序)如果安装了多个版本的 Java,可在 .zshrc 中写入:

1
2
3
4
5
6
7
8
9
10
# JDK 8
export JAVA_8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home"
# JDK 15
export JAVA_15_HOME="/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home"
# 默认JDK 8
export JAVA_HOME=$JAVA_8_HOME

# alias命令动态切换JDK版本
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk15="export JAVA_HOME=$JAVA_15_HOME"

之后可以使用 jdk8jdk15 切换 java 版本。

Xcode

配置 GitHub

登录 GitHub:需要配置 Personal access tokens,命名如 Weipeng's MacBook Pro - Xcode,打开的权限:

  • repo
  • admin:org
  • admin:public_key
  • user

代码块

将备份的代码块,即 CodeSnippets 文件夹拖入 ~/Library/Developer/Xcode/UserData 目录内。

偏好设置

Preferences 选中 Behaviors,根据 图 - 1图 - 2 进行设置。

图 - 1: Xcode 偏好设置1

图 - 2: Xcode 偏好设置2

命令行快捷键

创建文件 open_terminal.sh,写入代码:

1
2
3
4
5
6
#!/bin/sh
if [ -n "$XcodeProjectPath" ]; then
open -a iTerm "$XcodeProjectPath"/..
else
open -a iTerm "$XcodeWorkspacePath"/..
fi

之后将脚本保存 ~/Local/Scripts/ 目录下,然后在该目录下执行 chmod +x open_terminal.sh 将脚步设为可执行。

打开 Xcode 的 Preferences,选中 Behaviors,新建并命名为 Open Terminal,快捷键设置为 Control + Command + /,路径选择脚本所在路径。

图 - 3: 打开命令行脚本设置

Visual Studio Code

Shift + Command + P 之后找到 Shell Command: Install "code" command in PATH,运行。

登录同步账号:qiweipeng@hotmail.com,登录 Github。

PicGo

打开[上传前重命名]和[时间戳重命名]。

GitHub 图床设置:

图 - 4: PicGo 中 GitHub 图床设置

其中需要配置 Personal access tokens,命名如 Weipeng's MacBook Pro - PicGo,打开的权限:

  • repo

Trojan

User Rules 配置:

1
2
3
4
5
6
7
8
||notion.so
||*.notion.so
||github.com
||*.github.com
||githubusercontent.com
||*.githubusercontent.com
||dribbble.com
||*.dribbble.com