前言

纠结了很久新出的MacBook Air M2,但是将配置拉到16+512后价格太贵,感觉没有Pro划算,于是在第三方购入MacBook Pro 14寸(2021)笔记本(M1 Pro芯片)。

终端相关

使用代理

1
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

使用文本编辑器打开

1
2
# -a后的参数指定应用
open -a TextEdit /Users/xxx/.jupyter/jupyter_notebook_config.py

查看能耗

1
sudo powermetrics

应用程序已损坏

1
sudo xattr -r -d com.apple.quarantine 路径

查看睡眠情况

1
2
3
pmset -g
pmset -g assertions
pmset -g log | grep DarkWake

查看硬盘写入情况

1
2
brew search smartmontools
smartctl -a disk0 # 查看Data Units Written对应的数据量

优化睡眠

1
2
sudo pmset -a tcpkeepalive 0
sudo pmset -a powernap 0

NTFS支持

如果要使用NTFS类型的外接硬盘,建议安装Mounty for NTFS。

1
brew install --cask mounty

brew相关开发环境

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

安装完成后提示:/opt/homebrew/bin is not in your PATH.

1
2
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/zhangzhaoming/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

安装Node

1
brew install node

安装hexo

1
sudo npm install -g hexo-cli

Java环境

JDK下载地址:https://www.azul.com/downloads/?version=java-8-lts&os=macos&architecture=arm-64-bit&package=jdk

Maven:https://blog.csdn.net/qq1808814025/article/details/112306747

PyTorch环境

先安装Anaconda,已对M1支持:https://www.anaconda.com/products/distribution#Downloads

然后安装PyTorch

1
conda install pytorch torchvision -c pytorch

测试

1
2
3
4
5
6
7
8
9
10
11
12
(base) ➜  ~ python
Python 3.9.12 (main, Apr 5 2022, 01:52:34)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x = torch.rand(5, 3)
>>> print(x)
tensor([[0.1095, 0.4034, 0.1430],
[0.2069, 0.9830, 0.0649],
[0.3715, 0.0530, 0.2425],
[0.3672, 0.1780, 0.9665],
[0.8853, 0.8241, 0.9443]])

最后配置PyCharm:Preferences -> Python Interpreter -> Add -> System Interpreter -> 选择路径(默认:/Users/XXX/opt/anaconda3/python.app/Contents/MacOS/python)

Docker

https://docs.docker.com/desktop/mac/apple-silicon/

1
2
3
4
5
# Redis
docker run -d --name redis -p 6379:6379 redis:latest redis-server --appendonly yes --requirepass 密码

# Nginx
docker run -d -p 3344:80 --name nginx --privileged=true -v /Users/xxx/files/project/docker-mount-file/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /Users/xxx/files/project/docker-mount-file/nginx/html:/etc/nginx/html -v /Users/xxx/files/project/docker-mount-file/nginx/log:/var/log/nginx nginx

修改容器配置文件

1
2
3
4
5
6
# 查看ResolvConfPath参数,但是Mac中没有这个路径
docker inspect 容器ID
# 使用下列命令加载
docker run -it --name docker_vm --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh
# 进入容器后,找到config配置文件
/var/lib/docker/containers/容器ID

进程重启

1
killall Docker && open /Applications/Docker.app

外接显示器

开启hidpi

手上只有个15.6寸的1080p显示器,接上后字体有点小,缩小分辨率又比较模糊。安装BetterDisplay后开启hidpi即可解决,在GitHub上就能找到这个软件。

使用BetterDisplay开启hidpi的时候要注意,如果系统<12.4,只能使用dummy镜像方式开启,且不能关闭BetterDisplay。这种方式在笔记本休眠后启动有概率出现外接显示器闪屏的现象。

闪屏问题参考:https://github.com/xzhih/one-key-hidpi/issues/213

如果系统≥12.4,使用smooth scaling feature即可完美启动hidpi(我选择的是1536*864),启动后可以将BetterDisplay卸载。

去除刘海(不建议)

还发现个有趣的地方,下载rdm for mac调整主显示屏分辨率至1512*945(原来是1512*982),可以将刘海隐藏起来,但这样就相当于变成13寸mbp的屏幕了。

备份iPhone

将iPhone连接到Mac上,打开访达,可以对手机进行备份。备份的内容在/Users/用户名/Library/Application Support/MobileSync/文件夹下。

优点

1.音响给力,现在放歌都不外接蓝牙音箱了。

2.屏幕给力,有点后悔没上16寸,但要贵3k,不如买个4k显示器。

3.开发环境配置较方便,兼容性还行。

兼容问题

1.对比safari游览器,chrome能耗更高,但在可接受范围内。

2.sourcetree对m1芯片适配存在问题,发热严重,改用终端+GitHub Desktop。

3.对1080p外接显示器支持较差。

4.尽量安装通用程序,不要安装Intel类型程序,因为转译运行会损耗部分性能。可以先到 https://isapplesiliconready.com/zh 查询目标软件是否适配Apple Silicon。

5.笔记本合盖休眠后唤醒有概率出现意外重启,下面是部分错误报告,可能是便携显示器电源管理存在问题。

1
2
3
4
5
6
7
panic(cpu 4 caller 0xfffffe001be645b4): "AppleATCDPHDMIPort(atc3-dpphy)::enqueuePortMessage(0x1000002be): _messageQueue.enqueue(\"Unplug\") failed! Please file a radar under `AppleANXDPTX | all`.\n" @AppleATCDPNativePort.cpp:264
Debugger message: panic
......
last started kext at 634403585717: com.apple.filesystems.smbfs 4.0 (addr 0xfffffe001adf4b50, size 65122)
loaded kexts:
com.tuxera.filesystems.tuxera_ntfs 2021.1.7
......