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。


