mac服务器配置

这篇文章上次修改于 11 个月前,可能部分内容已经不适用,如有疑问可询问作者。

mac服务器配置

入职啦,村里又发 mac 了 记一下配置过程

终端

iTerm2

可以装个 iTerm2 替代初始的 terminal 虽然俺更喜欢 vsc 的终端

zsh

可以把 zsh 设置成默认的

BASH
chsh -s /bin/zsh
Copy

然后开始装插件

BASH
# 美观的ohmyzsh
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 自动补全
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# 语法高亮检查
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Copy

最后改一下~/.zshrc 的 plugin 部分

BASH
plugins=(git
    zsh-autosuggestions
    zsh-syntax-highlighting
    z)
Copy

homebrew

安装

BASH
# 可以尝试使用国内镜像
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
Copy

咱们用的是 zsh,得在 zshrc 里配置一下

BASH
source /Users/bytedance/.profile
Copy

git

先生成 key 这里用的是 ed25519,比起 rsa 更安全、更快

BASH
ssh-keygen -t ed25519 -C "matto2024@163.com" # 把邮箱改成自己的
Copy

git 一般是自带的 生成好主要是需要配置一下 ssh config 和 git config 前者用途是为不同的 Git 服务器(如 GitHub、GitLab、公司内部 Git)设置不同的 SSH 密钥 后者是配置 git 用户名和邮箱

~/.ssh/config 文件

BASH
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519
Copy

git config 配置

BASH
git config --global user.name "matto"
git config --global user.email "matto2024@163.com"
Copy

最后是需要在对应的 git 服务器上添加 ssh 的 pub key

多个 git 用户信息的配置

然而有的时候我们针对公司内的 git 和 自己的 github 需要配置不同的用户信息 我们可以在 gitconfig 里面来进行匹配,完成配置

BASH
# 这一串设置通过匹配当前仓库的remote.origin.url 来决定使用哪个gitconfig
# 这里匹配的是github和gitlab的git和https前缀
[includeIf "hasconfig:remote.*.url:git@github.com:*/**"]
    path = ~/.gitconfig-personal
[includeIf "hasconfig:remote.*.url:https://github.com/**"]
    path = ~/.gitconfig-personal

[includeIf "hasconfig:remote.*.url:git@gitlab.company.com:*/**"]
    path = ~/.gitconfig-personal
[includeIf "hasconfig:remote.*.url:https://gitlab.company.com/**"]
    path = ~/.gitconfig-personal
Copy

然后创建对应的 gitconfig-personal 文件

BASH
touch ~/.gitconfig-personal
Copy

再在里面填入

BASH
[user]
    name = matto
    email = matto2023@163.com
Copy

打开一个使用 github 的仓库,然后执行

BASH
git config user.name
Copy

来看看有没有成功

前端环境

node

BASH
brew install fnm
Copy

然后装 node

BASH
fnm install --lts
Copy

会发现安装的 node 指令用不了 需要在.zshrc 里配置一下

BASH
# 基础配置 - 必需
eval "$(fnm env --use-on-cd)"

# 可选的额外配置
export PATH="/opt/homebrew/bin:$PATH"  # 确保 brew 安装的 fnm 在 PATH 中

# 自动完成配置(可选)
# 添加 fnm 的自动完成支持
eval "$(fnm completions --shell zsh)"

# 自动切换 node 版本(可选)
# 如果目录下有 .node-version 或 .nvmrc 文件,会自动切换到对应版本
eval "$(fnm env --use-on-cd)"
Copy