Mac常用环境配置

前言

Mac各种环境和镜像配置。

Github设置DNS

打开 终端(Terminal)

输入以下命令以编辑 hosts 文件:

1
sudo vim /etc/hosts

输入你的 Mac 登录密码(输入时不会显示字符,正常输入后回车)

i 键进入编辑模式

在文件末尾添加你查到的 IP 映射,例如:

1
2
3
4
5
# GitHub Start
20.205.243.166 github.com
199.232.69.194 github.global.ssl.fastly.net
185.199.111.153 assets-cdn.github.com
# GitHub End

Esc 键退出编辑模式,然后输入 :wq 并回车保存退出

Homebrew配置

一键安装Homebrew

1
/bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

推荐使用阿里源

查看源

1
cd "$(brew --repo)" && git remote -v

NodeJS环境

安装CURL

1
brew install curl

安装NVM

1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

NVM镜像

永久设置

将镜像地址写入 shell 配置文件(如 ~/.zshrc~/.bash_profile):

  1. 打开配置文件(以 zsh 为例):
1
vi ~/.zshrc
  1. 在文件中添加以下行:
1
2
3
4
5
6
# 使用 npmmirror
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
  1. 保存并重新加载配置:
1
source ~/.zshrc

验证是否生效

你可以尝试安装一个 Node 版本,观察下载链接是否来自镜像:

1
nvm install 22

切换版本

1
nvm alias default 22.22.1

NPM镜像

1
2
3
npm config set registry https://registry.npmmirror.com/
npm cache clean -f
npm config list

图床

PicGo不好安装这里使用

uPic

https://gitee.com/gee1k/uPic/releases

快捷指令

提交博客

添加运行Shell脚本

1
2
3
4
5
6
cd /Users/psvmc/project/myblog

git add .
COMMIT_MSG="Auto commit $(date '+%Y-%m-%d %H:%M')"
git commit -m "$COMMIT_MSG"
git push origin master

添加显示通知

免密登录

1
ssh-keygen -t ed25519 -C "183518918@qq.com"

使用 scp(推荐)

1
scp ~/.ssh/id_ed25519.pub root@39.104.203.241:/tmp/id_ed25519.pub

然后登录服务器,追加到 authorized_keys

1
2
3
4
5
ssh root@39.104.203.241
mkdir -p ~/.ssh
cat /tmp/id_ed25519.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

SSH客户端

Xterminal

同时支持SSH和RDP,可以开启配置同步(需要付费)。

功能比FinalShell更强大,个人感觉比FinalShell更好用。

Xterminal - 更好用的开发工具,但不止于(SSH/控制台/More)

SourceTree

https://www.sourcetreeapp.com/?spm=5176.28103460.0.0.38f97d838IdJIu