Setting Up Your D Development Environment
To write and run D code you need a compiler (DMD, LDC, or GDC) and, for anything beyond a single file, DUB -- D's official package and build manager. DMD is the reference compiler maintained by the D Language Foundation and is the fastest to compile with, making it the default choice while learning; LDC (LLVM-based) and GDC (GCC-based) produce more optimized native binaries and are typically used for release builds or targets DMD doesn't support well, such as ARM or WebAssembly.
Cricket analogy: Like choosing your primary kit for the season, a lightweight bat for quick net practice (DMD) versus a heavier, tournament-grade bat you switch to for the big final (LDC/GDC), you pick the tool that matches the stakes of the innings.
Installing a D Compiler
The simplest path on Linux or macOS is the official install script: curl -fsS https://dlang.org/install.sh | bash -s dmd, which downloads DMD, the standard library (Phobos), and the runtime (druntime) into a local directory and prints a source command to add them to your PATH. Windows users can grab the DMD installer (.exe) directly from dlang.org, or install via choco install dmd with Chocolatey; Linux users on Debian/Ubuntu can alternatively add the D APT repository, and macOS users can run brew install dmd. Once installed, dmd --version should print the compiler version, confirming the toolchain is on your PATH.
Cricket analogy: Like different regional cricket boards each running their own trials to select players, the install script, Chocolatey, and Homebrew are different selection paths that all land you on the same national squad: a working DMD compiler.
# Linux/macOS: official install script (installs DMD by default)
curl -fsS https://dlang.org/install.sh | bash -s dmd
# macOS via Homebrew
brew install dmd
# Windows via Chocolatey
choco install dmd
# Verify installation
dmd --version
DUB: D's Package and Build Manager
DUB is bundled with the official DMD installer and manages dependencies, build configurations, and project scaffolding much like npm for Node.js or cargo for Rust. Running dub init myproject scaffolds a new project with a dub.json (or dub.sdl) manifest describing the package name, dependencies, and target type; dub build compiles it, dub run compiles and executes it in one step, and dub add <package> fetches a dependency from the central registry at code.dlang.org and records it in dub.selections.json for reproducible builds.
Cricket analogy: Like a team manager filing the official playing XI and squad list before a match, dub init creates the dub.json manifest listing your project's dependencies, which DUB then locks into dub.selections.json the way a captain locks in the final lineup.
dub init myproject
cd myproject
{
"name": "myproject",
"description": "A minimal D application",
"authors": ["Your Name"],
"dependencies": {
"vibe-d": "~>0.9.5"
},
"targetType": "executable"
}
dub add vibe-d # fetch a dependency from code.dlang.org
dub build # compile the project
dub run # compile and run in one step
Verifying Your Setup
After installing, create a throwaway file test.d containing a main() that calls writeln, then run it with rdmd test.d -- rdmd is a companion tool that compiles and immediately runs a single file without leaving a binary behind, ideal for quick checks and scripting. If rdmd reports "command not found," the install script's PATH export likely wasn't sourced in your current shell session; re-run the source line it printed, or add it to your .bashrc/.zshrc so it persists across terminal sessions.
Cricket analogy: Like a quick net session before the actual match to check your form is right, running rdmd test.d compiles and runs a throwaway file in one step, giving instant feedback without leaving equipment (a binary) lying around afterward.
Mixing multiple installed D toolchains (e.g., an apt-installed dmd package for Debian/Ubuntu alongside a manually installed one from the official script) on PATH can cause version conflicts. If dub build behaves unexpectedly or picks the wrong compiler version, run which dmd and dmd --version to confirm exactly which toolchain is active before debugging further.
- A D toolchain requires a compiler (DMD, LDC, or GDC) plus DUB, the official package and build manager.
- DMD is the reference compiler with the fastest compile times, ideal for daily development; LDC and GDC produce more optimized binaries for release builds.
- Install DMD via the official script (curl ... install.sh), Homebrew (macOS), Chocolatey (Windows), or a Linux package repository.
- dub init scaffolds a new project with a dub.json manifest; dub build compiles it and dub run compiles and runs it in one step.
- dub add fetches dependencies from the central registry at code.dlang.org and records exact versions in dub.selections.json for reproducible builds.
- rdmd compiles and runs a single file in one command without leaving a persistent binary, ideal for quick tests.
- Run dmd --version after installing to confirm the compiler is correctly on your PATH.
Practice what you learned
1. What is DUB in the D ecosystem?
2. Which command scaffolds a new DUB project?
3. What file does DUB use to lock exact dependency versions for reproducible builds?
4. What does rdmd do differently from dmd?
5. Where does DUB fetch third-party packages from by default?
Was this page helpful?
You May Also Like
What Is the D Programming Language?
An introduction to the D programming language -- its history, design philosophy, and the features that set it apart from C++, Java, and Go.
Your First D Program
Write, compile, and run your first D program, and understand the module, import, and main() concepts every D file relies on.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics