environment-setup-guide
指导开发者设置开发环境,包括安装合适的工具、依赖项和配置。
Environment Setup Guide
Overview
Help developers set up complete development environments from scratch. This skill provides step-by-step guidance for installing tools, configuring dependencies, setting up environment variables, and verifying the setup works correctly.
When to Use This Skill
How It Works
Step 1: Identify Requirements
I'll help you determine what needs to be installed:
Step 2: Check Current Setup
Before installing anything, I'll help you check what's already installed:
# Check versions of installed tools
node --version
python --version
git --version
docker --versionStep 3: Provide Installation Instructions
I'll give platform-specific installation commands:
Step 4: Configure the Environment
Help set up:
Step 5: Verify Installation
Provide verification steps to ensure everything works:
Examples
Example 1: Node.js Project Setup
## Setting Up Node.js Development Environment\Prerequisites
macOS, Linux, or Windows Terminal/Command Prompt access Internet connection Step 1: Install Node.js
macOS (using Homebrew):
\\\bashInstall Homebrew if not installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Install Node.js
brew install node
\\Linux (Ubuntu/Debian):
\\\bashUpdate package list
sudo apt updateInstall Node.js and npm
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
\\\Windows (using Chocolatey):
\\\powershellInstall Chocolatey if not installed
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))Install Node.js
choco install nodejs
\\\Step 2: Verify Installation
\
\\bash\
node --version # Should show v20.x.x or higher
npm --version # Should show 10.x.x or higher
\\Step 3: Install Project Dependencies
\
\\bashClone the repository
git clone https://github.com/your-repo/project.git
cd projectInstall dependencies
npm install
\\\Step 4: Set Up Environment Variables
Create a \
.env\file:
\\\bashCopy example environment file
cp .env.example .envEdit with your values
nano .env
\\\Example \
.env\content:
\\\\
NODE_ENV=development
PORT=3000
DATABASE_URL=postgresql://localhost:5432/mydb
API_KEY=your-api-key-here
\\Step 5: Run the Project
\
\\bashStart development server
npm run devShould see: Server running on http://localhost:3000
\\\Troubleshooting
Problem: "node: command not found"
Solution: Restart your terminal or run \source ~/.bashrc\(Linux) or \source ~/.zshrc\(macOS)Problem: "Permission denied" errors
Solution: Don't use sudo with npm. Fix permissions:
\\\bash\
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
\\
Example 2: Python Project Setup
## Setting Up Python Development Environment\Step 1: Install Python
macOS:
\\\bash\
brew install python@3.11
\\Linux:
\\\bash\
sudo apt update
sudo apt install python3.11 python3.11-venv python3-pip
\\Windows:
\\\powershell\
choco install python --version=3.11
\\Step 2: Verify Installation
\
\\bash\
python3 --version # Should show Python 3.11.x
pip3 --version # Should show pip 23.x.x
\\Step 3: Create Virtual Environment
\
\\bashNavigate to project directory
cd my-projectCreate virtual environment
python3 -m venv venvActivate virtual environment
macOS/Linux:
source venv/bin/activateWindows:
venv\Scripts\activate
\\Step 4: Install Dependencies
\
\\bashInstall from requirements.txt
pip install -r requirements.txtOr install packages individually
pip install flask sqlalchemy python-dotenv
\\\Step 5: Set Up Environment Variables
Create \
.env\file:
\\\\
FLASK_APP=app.py
FLASK_ENV=development
DATABASE_URL=sqlite:///app.db
SECRET_KEY=your-secret-key-here
\\Step 6: Run the Application
\
\\bashRun Flask app
flask runShould see: Running on http://127.0.0.1:5000
\\\
Example 3: Docker Development Environment
## Setting Up Docker Development Environment\Step 1: Install Docker
macOS:
\\\bash\
brew install --cask dockerOr download Docker Desktop from docker.com
\\Linux:
\\\bashInstall Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.shAdd user to docker group
sudo usermod -aG docker $USER
newgrp docker
\\Windows:
Download Docker Desktop from docker.comStep 2: Verify Installation
\
\\bash\
docker --version # Should show Docker version 24.x.x
docker-compose --version # Should show Docker Compose version 2.x.x
\\Step 3: Create docker-compose.yml
\
\\yaml
version: '3.8'services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=development
- DATABASE_URL=postgresql://postgres:password@db:5432/mydb
volumes:
- .:/app
- /app/node_modules
depends_on:
- dbdb:
image: postgres:15
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=mydb
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/datavolumes:
postgres_data:
\\\Step 4: Start Services
\
\\bashBuild and start containers
docker-compose up -dView logs
docker-compose logs -fStop services
docker-compose down
\\\Step 5: Verify Services
\
\\bashCheck running containers
docker psTest database connection
docker-compose exec db psql -U postgres -d mydb
\\\
Best Practices
✅ Do This
❌ Don't Do This
Common Pitfalls
Problem: "Command not found" after installation
Symptoms: Installed tool but terminal doesn't recognize it
Solution:
# Check PATH
echo $PATHAdd to PATH (example)
export PATH="/usr/local/bin:$PATH"Problem: Permission errors with npm/pip
Symptoms: "EACCES" or "Permission denied" errors
Solution:
# Fix npm permissions
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrcProblem: Port already in use
Symptoms: "Port 3000 is already in use"
Solution:
# Find process on port 3000
lsof -i :3000Kill process
kill -9 <PID>Or use different port
PORT=3001 npm startProblem: Database connection fails
Symptoms: "Connection refused" or "Authentication failed"
Solution:
# Check if PostgreSQL is running
sudo systemctl status postgresqlTest connection
psql -h localhost -U postgres -d mydbSetup Script Template
Create a setup.sh script to automate setup:
#!/bin/bashecho "🚀 Setting up development environment..."
Check prerequisites
<div class="overflow-x-auto my-6"><table class="min-w-full divide-y divide-border border border-border"><thead><tr><th class="px-4 py-2 text-left text-sm font-semibold text-foreground bg-muted/50">command -v node >/dev/null 2>&1</th><th class="px-4 py-2 text-left text-sm font-semibold text-foreground bg-muted/50">{ echo "❌ Node.js not installed"; exit 1; }</th></tr></thead><tbody class="divide-y divide-border"></tbody></table></div>echo "✅ Prerequisites check passed"
Install dependencies
echo "📦 Installing dependencies..."
npm installCopy environment file
if [ ! -f .env ]; then
echo "📝 Creating .env file..."
cp .env.example .env
echo "⚠️ Please edit .env with your configuration"
fiRun database migrations
echo "🗄️ Running database migrations..."
npm run migrateVerify setup
echo "🔍 Verifying setup..."
npm run test:setupecho "✅ Setup complete! Run 'npm run dev' to start"
Related Skills
@brainstorming - Plan environment requirements before setup@systematic-debugging - Debug environment issues@doc-coauthoring - Create setup documentation@git-pushing - Set up Git configurationAdditional Resources
Pro Tip: Create a setup.sh or setup.ps1 script to automate the entire setup process. Test it on a clean system to ensure it works!