环境设置
设置你的 development 环境: 安装 language 运行时, editor, and tools 到开始 coding effectively.
你将学到
- 什么 development 环境是 and 它的键 组件
- 如何 安装 language 运行时 (节点.js, Python, etc.)
- 选择 and 配置 code editor or IDE
- 包 managers and 安装项目 dependencies
- 验证你的设置使用首先运行 program
概念讲解
Environment Setup
A development environment is the collection of tools on your computer that lets you write, run, and test code. Before you can program, you need three things: a language runtime (the engine that executes your code), a code editor (where you write the code), and a package manager (to install libraries). Setting these up correctly is a one-time investment that pays off every day.
Installing a Language Runtime
runtime 是 the software that executes your code. For JavaScript outside the browser, that runtime is Node.js. For Python, it is the Python interpreter. You download the runtime from the official website, run the installer, and verify it works:
# After installing Node.js, verify:
node --version # e.g., v20.10.0
npm --version # e.g., 10.2.3
# After installing Python, verify:
python --version # e.g., Python 3.12.0
If these commands print version numbers, the runtime is installed and accessible from your terminal. If you get "command 不找到," the installation did not add the tool to your system path — a common issue with a known fix for each operating system.
Choosing a Code Editor
A code editor is where you write your programs. The most popular choice today is Visual Studio Code (VS Code) — it is free, lightweight, and has a rich ecosystem of extensions. Key features to configure:
- Syntax highlighting — colors that make code structure visible.
- Auto-completion — suggests names as you type.
- Integrated terminal — run commands without leaving the editor.
- Debugger — set breakpoints and step through code.
- Extensions — add language support, linters, and formatters.
An IDE (Integrated Development Environment) like WebStorm or PyCharm includes more features out of the box but is heavier. For beginners, VS Code is the best starting point.
Package Managers
A package manager installs third-party libraries (called packages or dependencies). For Node.js, it is npm (installed with Node) or pnpm. For Python, it is pip. You use it to install libraries that others have published, so you do not have to reinvent the wheel:
npm install axios # install a library for HTTP requests
pip install requests # same concept, for Python
The package manager downloads the library, resolves its own dependencies, and makes it available to your code via import.
Verifying Your Setup
After installation, write a tiny program to confirm everything works end-to-end:
# Create a file: hello.js
echo 'console.log("设置工作!")' > hello.js
node hello.js # should print: Setup works!
If that runs, your environment is ready. You have a runtime, an editor, and a package manager — the three pillars of development. From here, every project you start builds on this foundation.
示例代码
# Step 1: Check if Node.js is installed
node --version
# If not found, download from https://nodejs.org and install
# Step 2: Check npm (comes with Node.js)
npm --version
# Step 3: Create a project directory
mkdir my-first-project
cd my-first-project
# Step 4: Initialize a new Node.js project
npm init -y
# This creates package.json — the project's config file
# Step 5: Install a useful library
npm install chalk # a library for colored terminal output
# Step 6: Write your first program
cat > index.js << 'EOF'
import chalk from "chalk";
console.log(chalk.green("Environment setup complete!"));
console.log(chalk.blue("You are ready to code."));
EOF
# Step 7: Run it
node index.js
# Output (in green): Environment setup complete!
# Output (in blue): You are ready to code.
这个是 完整环境设置 script: 检查运行时, 创建项目, initialize 它, 安装 dependency, 编写 program, and 运行它. 如果所有 steps succeed, 你的 development 环境是 fully functional.
动手试一试
- Dockerfile Generator
Docker 创建 reproducible development 环境. Generate Dockerfile 到 see 如何环境是 定义 as code.
- 环境 File Generator
环境变量配置你的设置. Generate .环境 files 到理解如何环境配置工作.
常见错误
错误写法
安装运行时但 不验证它 是 on 系统 PATH.
正确做法
之后 installation, 运行节点 --version or python --version in terminal. 如果你 获取 'command 不找到', tool 是不 on 你的 PATH. Reinstall and 检查 '添加到 PATH' option, or manually 添加安装 directory.
错误写法
安装全局包 当项目-局部包 是更多 appropriate.
正确做法
Use npm 安装 <包> (局部) for 项目 dependencies, 不 npm 安装 -g <包> (全局). 全局包 是 harder 到 manage and 能 cause version conflicts 之间项目.
错误写法
Using outdated 运行时 version 那个 lacks modern features.
正确做法
检查 for LTS (长 Term Support) versions. 节点.js LTS versions 是偶数-numbered (18, 20, 22). Use version manager 如 nvm or fnm 到切换 versions 每项目.
相关资源
相关速查表
- Bash Cheatsheet
Terminal commands for managing 你的 development 环境 and 安装 tools.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。