MacOS 开发环境配置

Mac 配置开发环境非常简单,只需要安装 brew 包管理工具,就可以一键搭建开发环境,而且 terminal 就像是 linux 下一样,非常适合开发。brew 源可能网络不太稳定,建议安装 Shadowrocket,感受丝滑的安装体验。

我平时写 java、python、golang、node.js 比较多。我需要安装 JDK、miniconda、golang、nvm。另外 还需要安装一些辅助开发工具,比如:git、chrome、postman、vscode,最后 JetBrains IDE 是必不可少的。

java

1
brew install --cask temurin21

java –version

M 系列不支持低版本 jdk,如果要使用 jdk 1.8 可以在开发中 idea 中设置语法的版本

miniconda

1
brew install --cask miniconda

conda -V

golang

1
brew install go

编辑 .zshrc

1
2
3
# golang
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

go version

rust

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

编辑 .zshrc

1
2
3
# rust
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup

rustc –version

nvm

https://formulae.brew.sh/formula/nvm

1
brew install nvm

编辑 .zshrc

1
2
3
4
5
6
7
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# 镜像
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/
export npm_config_registry=https://registry.npmmirror.com

nvm version

JetBrains IDE

这个没什么好说的,到官网选择自己系统的版本安装就可以。需要注意的是 intel 使用 macOS (dmg), M 系列使用 macOS Apple Silicon (dmg)

历史版本官网没有给入口,可以将后缀改为 other.html 进去历史版本下载页面,例如:https://www.jetbrains.com/idea/download/other.html ,遵守稳定大于最新的原则。另外还有一个神秘网址:https://3.jetbra.in

gcc

MacOS 自带

gcc -v

git

1
brew install git

git –version

Android Studio

https://developer.android.com/studio/archive

编辑 .zshrc

1
2
3
4
# android
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/platform-tools

Xcode

可以在 AppStore 直接下载 Xcode,如果提示 MacOS 版本低无法安装,可以直接去官网下载历史版本

https://developer.apple.com/download/all/?q=xcode

命令行

terminal 可以满足我的需求,但是只支持一些基本的功能。如果你不想每次通过命令连接服务器,可以使用 .ssh 脚本,参考下面的代码,关键占位改为自己的连接配置

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
28
29
#!/usr/bin/expect -f

set host {IP}
set port {Port}
set user {Username}
set password {Password}
set timeout 30

spawn ssh -p $port $user@$host

expect {
"Are you sure you want to continue connecting" {
send "yes\r"
exp_continue
}
"password:" {
send "$password\r"
}
timeout {
puts "Error: Connection timed out."
exit 1
}
eof {
puts "Error: Connection failed or was closed."
exit 1
}
}

interact

再推荐几个比较强大的 ssh 软件

  1. iTerm2
  2. Tabby
  3. Termius

其他软件

这里列出对应软件的官网,自行下载安装即可,需要注意:M 系列是 arm64 架构

postman:https://www.postman.com/

vscode:https://code.visualstudio.com/

chrome:https://www.google.com/intl/zh-CN/chrome/

PS

关于国内源的配置,自行去搜索引擎查找最新国内源地址。

如果外接鼠标,不习惯鼠标滚轮的自然滚动,可以使用 Scroll Reverser 单独设置触摸板和鼠标滚轮的滚动方式。

其他一些通讯软件,能在 appstore 找到的,优先从 appstore 安装。

常见问题

Goland 2022 Debug 实效

原因是 Goland 2022 内置的 dlv 只支持到 goland 1.20,如果安装的 golang 版本高于 1.20,那么在端点调试的时候卡住。

解决办法:

  • 降级 golang <= 1.20 或者升级 Goland

  • 编译最新版的 dlv,替换掉 Goland 内置的 dlv

    1
    2
    3
    4
    # mac m4
    git clone https://github.com/go-delve/delve
    cd delve
    go build -o /Applications/GoLand.app/Contents/plugins/go-plugin/lib/dlv/macarm/dlv ./cmd/dlv

总结

开发选 Mac 绝对没毛病,缺点就是均价贵,而且不适合玩游戏,PJ 软件也比较少。Mac + Win 专机专用或许是最好的选择。