跳到主要内容
极客日志极客日志面向AI+效率的开发者社区
首页博客我的书AI学习GitHub 精选镜像AI 生图工具UI配色美学关于
搜索内容 / 工具 / 仓库 / 镜像...⌘K搜索
注册
博客列表
编程语言SaaSPay

GitHub Codespaces 开发环境搭建与使用

介绍 GitHub Codespaces 云开发环境的搭建与使用。支持 2 核/4 核配置,提供每月免费时长与存储额度。默认镜像集成多种开发工具(Python、Java、GCC 等),可自定义超时设置及编辑器主题。适用于远程开发、嵌入式编译(如树莓派内核)等场景。需注意计费规则,超出免费额度后会产生费用,建议监控使用情况。相比本地环境,云端方案便携性更强,但体验略有差异。

二进制发布于 2026/3/25更新于 2026/9/1084 浏览
GitHub Codespaces 开发环境搭建与使用

GitHub Codespaces 开发环境搭建与使用

1 基本说明

近期计划进行 SOC 项目深度开发,需要 Linux 开发环境。原本考虑使用 WSL,但便携性和同步性不佳,在单位无法随时使用。曾考虑购买腾讯云或阿里云服务器,但促销资源多为国内节点,拉取外部代码不便。发现 GitHub Codespaces 提供免费额度,配置不错,且拉取 GitHub 代码速度较快,集成度高,决定尝试使用。

可选择 2 核或 4 核配置,使用时长相近。超时后 4 核费用较高。2 核配置如下:

CPU:2 核(vCPU) 内存:8 GB RAM 存储:32 GB(/workspaces 目录) 系统:Ubuntu Linux(默认镜像) 免费额度:每月 120 核时(core-hours) + 15 GB 存储(2 核机约 60 小时 / 月)

主界面如下:

文章配图

为最大化利用免费额度,建议调整超时时间。默认 30 分钟,可改为 5 分钟。位置在主界面 Settings -> Codespaces。

文章配图

在此可创建空白环境。

文章配图

后续可在设置中将界面调整为深色模式。

文章配图

默认环境未预装特定开发工具,点击左下角符号选择 Add Dev container configuration Files,将增加默认配置。

文章配图

默认配置文件为 .devcontainer/devcontainer.json,内容如下:

{"image":"mcr.microsoft.com/devcontainers/universal:2"}

直接使用该配置相当于创建包含全部开发工具的 Docker 容器。安装后可验证常用工具是否可用,甚至包含 Perl、PHP 等基础工具。

👋 Welcome to Codespaces! You are on our default image. - It includes runtimes and tools for Python, Node.js, Docker, and more. See the full list here: https://aka.ms/ghcs-default-image - Want to use a custom image instead? Learn more here: https://aka.ms/configure-codespace 🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1). 📝 Edit away, run your app as usual, and we'll automatically make it available for you to access. @dancejc ➜ /workspaces/codespaces-blank $ ls @dancejc ➜ /workspaces/codespaces-blank $ pwd /workspaces/codespaces-blank @dancejc ➜ /workspaces/codespaces-blank $ python Python 3.12.1 (main, May 6 2025, 20:30:25) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() @dancejc ➜ /workspaces/codespaces-blank $ gcc gcc: fatal error: no input files compilation terminated. @dancejc ➜ /workspaces/codespaces-blank $ make make: *** No targets specified and no makefile found. Stop. @dancejc ➜ /workspaces/codespaces-blank $ java -version openjdk version "21.0.7" 2025-04-15 LTS OpenJDK Runtime Environment Microsoft-11369942 (build 21.0.7+6-LTS) OpenJDK 64-Bit Server VM Microsoft-11369942 (build 21.0.7+6-LTS, mixed mode, sharing) @dancejc ➜ /workspaces/codespaces-blank $ php -version PHP 8.3.14 (cli) (built: May 6 2025 20:22:03) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.14, Copyright (c) Zend Technologies with Xdebug v3.4.2, Copyright (c) 2002-2025, by Derick Rethans @dancejc ➜ /workspaces/codespaces-blank $ perl -version This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux-gnu-thread-multi (with 60 registered patches, see perl -V for more detail) Copyright 1987-2019, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.

整体使用较为便捷。

2 创建树莓派 3 裸片环境

若需使用现有仓库,可直接在 Code 页面选择 Codespaces。

文章配图

系统将启动类 VS Code Web 版本。

文章配图

主界面显示已创建容器环境。

文章配图

若无默认 devcontainer 配置,需手动安装编译工具。

文章配图

Makefile 配置需适配当前工具链,经调整后编译成功。生成的内核文件为 kernel8.img。

支持右键下载至本地,相比传统云服务更为便捷。

文章配图

3 费用问题

需注意费用问题。即使未绑定支付方式,后台也会记录用量。欠费可能导致账号权限受限。

具体计费规则未详查,原计划仅使用免费额度。经核对,部分费用可被免费额度抵扣。如下:

$0.44
Showing currently applied usage and credits for your account.
Current usage for Mar 1 - Mar 31, 2026. Monthly quota resets in 1 day(s).
Included usage*
2,000 included Actions minutes
~$12.00 off*
$0
.5 GB included Actions storage
~$0.125 off*
$0
10 GB included Git LFS bandwidth
~$0.875 off*
$0
10 GB included Git LFS storage
~$0.70 off*
$0
1 GB included Packages data transfer
~$0.50 off*
$0
.5 GB included Packages storage
~$0.125 off*
$0
Included premium requests
~$0 off
$0
15 GB included Codespaces storage
~$1.05 off*
<$0.01
120 included Codespaces core hours
~$10.80 off*
$0.44

  • Included usage is an approximate amount based on current pricing.

存储和计算时长均有相应免费额度,日常使用通常足够。

4 总结

总体而言使用体验较好,但与本地 Linux 环境相比,体验略有差异。建议日常以 WSL 为主,兼顾手感与成本。外出或办公时可使用 Codespaces。

文章配图

目录

  1. GitHub Codespaces 开发环境搭建与使用
  2. 1 基本说明
  3. 2 创建树莓派 3 裸片环境
  4. 3 费用问题
  5. 4 总结

更多推荐文章

查看全部
  • Anaconda Prompt 环境下 GitHub 项目的 AI 辅助开发实践
  • FPGA 高速通信:Aurora64B/66B IP 使用指南
  • 滑动窗口算法精讲:两道经典题目解析
  • 前端地图开发基础:服务类型、坐标系与 SDK 简介
  • Java JDK 21 安装与环境配置指南
  • Pandas 数据统计包 6 种高效函数详解
  • Agent 和 Token 的区别:概念、关系与代码实现
  • Stable Diffusion v4.10 与 ComfyUI 整合包配置及问题解决方案
  • 人工智能进化全景:从专用工具到超级智能的跃迁
  • llama-cpp-python 安装配置与性能优化指南
  • 前端请求后端接口 404/405/500 状态码排查与解决
  • 兰斯顿·休斯《梦想》与《忧郁》诗作译文整理
  • Windows 本地运行 DeepSeek 大模型简易教程
  • GLM-4.6V-Flash 识别 Meme 图像背后的文化含义
  • 基于子集选择算法的负载均衡方案
  • 生成式 AI 生态系统实践与案例深度分析
  • Python aespy 包语法、参数与实战案例
  • FinalShell Windows 远程连接 Linux 服务器使用指南
  • Vue3+TypeScript 中 Promise<string> 转 string 类型错误解析及异步处理
  • 向量数据库:概念、原理与核心应用场景

相关免费在线工具

  • Base64 字符串编码/解码

    将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online

  • Base64 文件转换器

    将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online

  • Markdown转HTML

    将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online

  • HTML转Markdown

    将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online

  • JSON 压缩

    通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online

  • JSON美化和格式化

    将JSON字符串修饰为友好的可读格式。 在线工具,JSON美化和格式化在线工具,online