LinuxCommandLibrary

dub

Manage and build D language projects

TLDR

Interactively create a new D project

$ dub init [project_name]
copy

Non-interactively create a new D project
$ dub init [project_name] [[-n|--non-interactive]]
copy

Build and run a D project
$ dub
copy

Install dependencies specified in a D project's dub.json or dub.sdl file
$ dub fetch
copy

Update the dependencies in a D project
$ dub upgrade
copy

Display help
$ dub [[-h|--help]]
copy

SYNOPSIS

dub <command> [<options>] [<args> ...]

PARAMETERS

-h, --help
    Print help information

-q, --quiet
    Suppress output messages

-v, --verbose
    Verbose output

-d, --debug
    Enable debug logging

-b <build-type>, --build=<build-type>
    Specify build type (plain, debug, release, etc.)

-r <path>, --root=<path>
    Set root directory for dub project

-c <config>, --config=<config>
    Select configuration

-a <arch>, --arch=<arch>
    Target architecture

-f, --force
    Force redownload or rebuild

--compiler=<compiler>
    Select D compiler (dmd, ldc2, gdc)

DESCRIPTION

Dub is the official package manager and build tool for the D programming language. It simplifies project setup, dependency management, building, testing, and publishing packages. Dub uses a declarative recipe format in JSON or DUB files (dub.json or dub.sdl) to define configurations, dependencies, and build settings.

It supports multiple compilers like dmd, ldc, and gdc, with automatic toolchain detection. Key features include version resolution from the public registry at code.dlang.org, support for workspaces with multiple packages, and integration with version control. Dub fetches, builds, and caches dependencies efficiently, handling complex graphs with overrides and patches.

Ideal for D developers, it streamlines workflows similar to Cargo for Rust or npm for Node.js, reducing boilerplate and enabling reproducible builds.

CAVEATS

Requires a D compiler installed; cache at ~/.dub; network access for registry; subcommands have additional options via dub <command> --help.

COMMON SUBCOMMANDS

build - Build project(s)
run - Build and run
test - Run unit tests
generate - Generate project skeleton
fetch - Download dependencies
upgrade - Update packages
clean - Remove generated files
list - List packages
search - Search registry

PACKAGE RECIPE

Uses dub.json or dub.sdl for name, dependencies, configurations, build requirements.

HISTORY

Developed by Sönke Ludwig, first released in 2012. Evolved from simple build tool to full-featured manager; version 1.0 in 2015 stabilized core features. Actively maintained for D2.x ecosystem.

SEE ALSO

dmd(1), ldc2(1), gdc(1), make(1)

Copied to clipboard