{"path":"phases/00-setup-and-tooling/01-dev-environment","kind":"lesson","title":"Dev Environment","description":"Dev Environment: Your tools shape your thinking. Set them up once, set them up right. Set up Python 3.11+, Node.js 20+, and Rust toolchains from scratch.…","url":"https://aiengineeringfromscratch.com/lesson?path=phases%2F00-setup-and-tooling%2F01-dev-environment","sourceUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/00-setup-and-tooling/01-dev-environment/docs/en.md","markdown":"# Dev Environment\n\n> Your tools shape your thinking. Set them up once, set them up right.\n\n**Type:** Build\n**Languages:** Python, Node.js, Rust\n**Prerequisites:** None\n**Time:** ~45 minutes\n\n## Learning Objectives\n\n- Set up Python 3.11+, Node.js 20+, and Rust toolchains from scratch\n- Configure virtual environments and package managers for reproducible builds\n- Verify GPU access with CUDA/MPS and run a test tensor operation\n- Understand the four-layer stack: system, packages, runtimes, AI libraries\n\n## The Problem\n\nYou're about to learn AI engineering across 500+ lessons using Python, TypeScript, Rust, and Julia. If your environment is broken, every single lesson becomes a fight against tooling instead of learning.\n\nMost people skip environment setup. Then they spend hours debugging import errors, version conflicts, and missing CUDA drivers. We're going to do this once, properly.\n\n## The Concept\n\nAn AI engineering environment has four layers:\n\n```mermaid\ngraph TD\n    A[\"4. AI/ML Libraries\\nPyTorch, JAX, transformers, etc.\"] --> B[\"3. Language Runtimes\\nPython 3.11+, Node 20+, Rust, Julia\"]\n    B --> C[\"2. Package Managers\\nuv, pnpm, cargo, juliaup\"]\n    C --> D[\"1. System Foundation\\nOS, shell, git, editor, GPU drivers\"]\n```\n\nWe install bottom-up. Each layer depends on the one below it.\n\n```figure\ns0-env-stack\n```\n\n## Build It\n\n### Step 1: System Foundation\n\nCheck your system and install the basics.\n\n```bash\n# macOS\nxcode-select --install\nbrew install git curl wget\n\n# Ubuntu/Debian\nsudo apt update && sudo apt install -y build-essential git curl wget unzip\n\n# Windows (use WSL2)\nwsl --install -d Ubuntu-24.04\n```\n\n### Step 2: Python with uv\n\nWe use `uv` — it's 10-100x faster than pip and handles virtual environments automatically.\n\n```bash\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\nuv python install 3.12\n\nuv venv\nsource .venv/bin/activate  # or .venv\\Scripts\\activate on Windows\n\nuv pip install numpy matplotlib jupyter\n```\n\nVerify:\n\n```python\nimport sys\nprint(f\"Python {sys.version}\")\n\nimport numpy as np\nprint(f\"NumPy {np.__version__}\")\na = np.array([1, 2, 3])\nprint(f\"Vector: {a}, dot product with itself: {np.dot(a, a)}\")\n```\n\n### Step 3: Node.js with pnpm\n\nFor TypeScript lessons (agents, MCP servers, web apps).\n\n```bash\ncurl -fsSL https://fnm.vercel.app/install | bash\nfnm install 22\nfnm use 22\n\nnpm install -g pnpm\n\nnode -e \"console.log('Node', process.version)\"\n```\n\nThe fnm installer checks for `unzip` first and exits with `Not installing fnm due to missing dependencies.` when it is absent: on Linux it unpacks a zip archive, on macOS it installs through Homebrew. macOS ships `unzip`; Ubuntu, Debian, and WSL2 get it from the Step 1 apt line (`sudo apt install -y unzip` if you skipped that step).\n\n**macOS / Apple Silicon (M1/M2/M3/M4):** If the installer stops with `Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)`, your terminal is running under Rosetta 2 (`arch` prints `i386`) while Homebrew is a native arm64 build. Install fnm forcing arm64, wire it into your shell, then rerun the commands above from `fnm install 22`:\n\n```bash\narch -arm64 brew install fnm\necho 'eval \"$(fnm env --use-on-cd)\"' >> ~/.zshrc\nsource ~/.zshrc\n```\n\n### Step 4: Rust\n\nFor performance-critical lessons (inference, systems).\n\n```bash\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\n\nrustc --version\ncargo --version\n```\n\n### Step 5: Julia (Optional)\n\nFor math-heavy lessons where Julia shines.\n\n```bash\ncurl -fsSL https://install.julialang.org | sh\n\njulia -e 'println(\"Julia \", VERSION)'\n```\n\n### Step 6: GPU Setup (If You Have One)\n\n**NVIDIA (Linux / Windows):**\n\n```bash\nnvidia-smi\n\n# Install PyTorch with CUDA\nuv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124\n```\n\n**macOS / Apple Silicon (M1/M2/M3/M4):** There is no CUDA on a Mac — that's expected, not a failure. Do **not** pass `--index-url .../cuXXX` (those wheels are Linux/Windows only, so the install fails). Install the plain build, which includes Apple's MPS (Metal) GPU backend:\n\n```bash\nuv pip install torch torchvision torchaudio\n```\n\nVerify (works on any platform):\n\n```python\nimport torch\nprint(f\"CUDA available: {torch.cuda.is_available()}\")           # False on macOS — expected\nprint(f\"MPS available:  {torch.backends.mps.is_available()}\")   # True on Apple Silicon\nif torch.cuda.is_available():\n    print(f\"GPU: {torch.cuda.get_device_name(0)}\")\n```\n\nNo GPU? No problem. Most lessons work on CPU. For training-heavy lessons, use Google Colab or cloud GPUs.\n\n### Step 7: Verify the route you want to start\n\nRun every command in this lesson from the repository root, the directory that\ncontains `README.md` and `phases/`. The preflight checks only what you need to\nstart the selected route. It skips later tools by default so a new learner sees\none clear answer instead of a wall of warnings.\n\nStart the full beginner sequence:\n\n```bash\npython3 phases/00-setup-and-tooling/01-dev-environment/code/verify.py --route beginner\n```\n\nOr check only the route you want:\n\n```bash\npython3 phases/00-setup-and-tooling/01-dev-environment/code/verify.py --route ml-foundations\npython3 phases/00-setup-and-tooling/01-dev-environment/code/verify.py --route llm-engineering\npython3 phases/00-setup-and-tooling/01-dev-environment/code/verify.py --route agents\npython3 phases/00-setup-and-tooling/01-dev-environment/code/verify.py --route mcp\npython3 phases/00-setup-and-tooling/01-dev-environment/code/verify.py --route agent-skills\npython3 phases/00-setup-and-tooling/01-dev-environment/code/verify.py --route certification\n```\n\nAdd `--show-later` when you want the same preflight to inspect optional tools\nand dependencies used by later lessons. A missing later tool never blocks the\nselected route.\n\nEach failed required check includes the detected path or import error and an\nexact corrective command. The Agent Skills and certification routes also show\nmanual host checks because a Python script cannot prove that an AI host has\ndiscovered a skill or that your chosen skill scope is writable.\n\nWhen the beginner preflight passes, it prints the exact first runnable lesson:\n\n```text\nReady to start Beginner course.\nNext: python3 phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.py\n```\n\n## Use It\n\nYour environment is ready to start the route you checked. Install later tools\nwhen a lesson asks for them instead of blocking your first lesson on the whole\nstack. Here is what you will use across the curriculum:\n\n| Language | Used In | Package Manager |\n|----------|---------|-----------------|\n| Python | Phases 1-12 (ML, DL, NLP, Vision, Audio, LLMs) | uv |\n| TypeScript | Phases 13-17 (Tools, Agents, Swarms, Infra) | pnpm |\n| Rust | Phases 12, 15-17 (Performance-critical systems) | cargo |\n| Julia | Phase 1 (Math foundations) | Pkg |\n\n## Ship It\n\nThis lesson produces a verification script that anyone can run to check their setup.\n\nSee `outputs/prompt-env-check.md` for a prompt that helps AI assistants diagnose environment issues.\n\n## Exercises\n\n1. Run the verification script and fix any failures\n2. Create a Python virtual environment for this course and install PyTorch\n3. Write a \"hello world\" in all four languages and run each one\n"}
