环境配置指南

快速配置(5分钟)

系统要求

  • Node.js >= 18.0
  • npm >= 9.0 (或 pnpm / yarn)
  • Go >= 1.21 (用于项目实现)
  • 操作系统 - macOS / Linux / Windows (WSL2)

一键设置

# 1. 进入项目目录
cd /Users/zhangruobin/Episodes/Areas/interview-prepare

# 2. 安装文档依赖
npm install

# 3. 启动开发服务器
npm run dev

# 4. 打开浏览器
# http://localhost:5173

完成! 现在你可以开始学习了。


详细配置

1. Node.js安装

macOS

# 使用Homebrew
brew install node

# 或使用nvm(推荐)
brew install nvm
nvm install 18
nvm use 18

# 验证
node --version  # v18.x.x
npm --version   # 9.x.x

Linux (Ubuntu/Debian)

# 使用nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 18
nvm use 18

# 验证
node --version
npm --version

Windows

  1. 下载 Node.js LTS
  2. 运行安装程序,勾选"Add to PATH"
  3. 重启终端,验证:
    node --version
    npm --version

2. Go环境(项目实现用)

macOS

brew install go

# 验证
go version  # go version go1.21 or higher

Linux

wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz

# 添加到PATH(编辑 ~/.bashrc 或 ~/.zshrc)
export PATH=$PATH:/usr/local/go/bin

# 验证
go version

Windows

  1. 下载 Go安装程序
  2. 运行安装程序
  3. 验证:
    go version

3. 代码编辑器

VS Code (推荐)

# macOS
brew install visual-studio-code

# 或从 https://code.visualstudio.com 下载

推荐扩展:

# Go开发
code --install-extension golang.Go

# Markdown预览
code --install-extension yzhang.markdown-all-in-one

# 代码格式化
code --install-extension esbenp.prettier-vscode

GoLand / IntelliJ IDEA

4. 项目依赖安装

cd /Users/zhangruobin/Episodes/Areas/interview-prepare

# 使用npm(默认)
npm install

# 或使用pnpm(更快)
pnpm install

# 或使用yarn
yarn install

开发工作流

启动文档开发服务器

npm run dev

输出:

ℹ Server running at http://localhost:5173

实时编辑

  1. 打开浏览器 http://localhost:5173
  2. 编辑任何 .md 文件
  3. 保存后网页自动刷新

提交更改

git add .
git commit -m "Update: Day 1教学材料"
git push

常见命令

npm脚本

命令 说明
npm run dev 启动开发服务器(http://localhost:5173)
npm run build 生成静态网站到dist/文件夹
npm run preview 本地预览构建后的网站
npm run type-check 检查TypeScript类型

Go项目初始化

Day 1会要求初始化Go项目。快速命令:

# 创建项目目录
mkdir -p agent-runtime && cd agent-runtime

# 初始化Go module
go mod init github.com/yourname/agent-runtime

# 下载依赖
go get -u github.com/your/dependency

# 运行
go run cmd/api/main.go

IDE 配置建议

VS Code

创建 .vscode/settings.json

{
  "[go]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  },
  "[markdown]": {
    "editor.wordWrap": "on",
    "editor.formatOnSave": true
  },
  "files.exclude": {
    "**/.DS_Store": true,
    "**/node_modules": true
  }
}

Go开发设置

添加到 ~/.bashrc~/.zshrc

# Go相关
export GOPATH=$HOME/go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

# 使用国内镜像加速(可选)
export GOPROXY=https://goproxy.cn,direct

网络配置

使用国内镜像(中国用户)

npm镜像

# 临时使用
npm install -g cnpm --registry=https://registry.npmmirror.com

# 永久配置
npm config set registry https://registry.npmmirror.com

Go镜像

编辑 ~/.bashrc~/.zshrc

export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct

故障排查

npm install 失败

# 清理缓存
npm cache clean --force

# 删除node_modules和lock文件
rm -rf node_modules package-lock.json

# 重新安装
npm install

Node版本不兼容

# 检查当前版本
node --version

# 使用nvm切换版本
nvm list                # 查看已安装版本
nvm install 18          # 安装18
nvm use 18              # 使用18
nvm default 18          # 设为默认

端口5173被占用

# 查看占用进程
lsof -i :5173

# 或用其他端口
npm run dev -- --port 3000

rspress找不到

# 检查安装
npm list rspress

# 重新安装
npm install rspress@latest

性能优化

加快npm安装

# 使用pnpm(推荐,比npm快3-5倍)
npm install -g pnpm
pnpm install

# 使用npm工作区(monorepo支持)
npm install --legacy-peer-deps  # 如果有依赖冲突

加快Go项目编译

# 使用Go 1.21的新特性
export GOCACHE=~/.cache/go-build

# 启用并行编译
export GOMAXPROCS=4

# 构建时跳过测试
go build -v

文件结构

interview-prepare/ ├── rspress.config.ts # rspress配置文件 ├── package.json # Node项目配置 ├── docs/ # 文档源文件 │ ├── index.md # 首页 │ ├── quick_start.md # 快速开始 │ ├── quick_reference.md # 快速参考 │ ├── algorithms.md # 算法题库 │ ├── system_design_guide.md # 系统设计指南 │ ├── interview_prep.md # 面试准备 │ ├── deployment.md # 部署指南 │ ├── environment_setup.md # 本文件 │ └── faq.md # 常见问题 ├── weekplan/ # 周计划教材 │ ├── week1_overview.md │ ├── week1_day1.md │ ├── week1_day2.md │ ├── ... │ └── week4_day30.md ├── code-examples/ # 代码示例 │ ├── day1_complete.md │ └── ... ├── dist/ # 构建输出(npm run build生成) ├── node_modules/ # 依赖(npm install生成) └── PROGRESS.md # 学习进度追踪

下一步

  1. ✅ 环境配置完成
  2. 👉 启动开发服务器
  3. 🚀 开始学习Day 1

获得帮助