Installation, Compilers and Tooling
2.1 Installing
Verify: dmd --version, ldc2 --version, dub --version.
# Official install script (Linux/macOS): installs dmd/ldc/gdc + dub
curl -fsS https://dlang.org/install.sh | bash -s dmd
curl -fsS https://dlang.org/install.sh | bash -s ldc
source ~/dlang/dmd-2.111.0/activate # activate a toolchain
# Package managers
brew install dmd ldc dub
sudo apt install ldc dub # Debian/Ubuntu
winget install dlang.dmd # Windows (or the installer from dlang.org)2.2 Tools
dmd / ldc2 / gdc Compile and run scripts with automatic dependency tracking Package manager and build tool dscanner (D-Scanner) Linter and static analysis serve-d / code-d Language server / VS Code extension ddox / adrdox Test case reducer
Include C/C++ headers directly (#include in D files) Demangle D symbols
2.3 Hello, World
// hello.d
import std.stdio;
void main()
{
writeln("Hello, World!");
}dmd hello.d && ./hello
dmd -run hello.d # compile and run
rdmd hello.d # script-style
ldc2 -O3 -release hello.d # optimized build2.4 Scripts with Shebang
Single-file DUB scripts can embed dependencies:
#!/usr/bin/env rdmd
import std.stdio;
void main(string[] args) { writeln("Args: ", args[1 .. $]); }#!/usr/bin/env dub
/+ dub.sdl:
name "script"
dependency "mir-algorithm" version="~>3.22"
+/
void main() { import std.stdio; writeln("with deps"); }2.5 Creating a Project with DUB
dub init myapp # interactive: dub.json or dub.sdl
cd myapp
dub run # build + run
dub build --build=release
dub test # run unittests
dub add vibe-d # add a dependency2.6 Editor Setup
VS Code: the code-d extension (installs serve-d, dfmt, and D-Scanner).
IntelliJ (the intellij-dlang plugin), Vim/Neovim (serve-d via LSP), Emacs (d-mode + lsp), Visual Studio (Visual D), Sublime, Geany.