Installing DUB

DUB is the D language's official package manager, providing simple and configurable cross-platform builds. DUB can also generate VisualD and Mono-D package files for easy IDE support.

To install DUB, search your operating system's package manager or download the pre-compiled package for your platform. The Windows installer will perform all installation steps; for other archives, you will want to ensure the DUB executable is in your path. Installation from source on other platforms is as simple as installing the dmd development files and your system's libcurl-dev, then running ./ in the repository's folder.

Starting a new project

From your top-level source directory, run:

$ dub init myproject

This begins an interactive session:

Package recipe format (sdl/json) [json]:
Name [myproject]:
Description [A minimal D application.]: My first project
Author name [imadev]: My Name
License [proprietary]: Boost
Copyright string [Copyright © 2017, imadev]:
Add dependency (leave empty to skip) []:
Successfully created an empty project in '/home/imadev/src/myproject'.
Package successfully created in myproject

DUB has created a "myproject" directory containing a .gitignore, a dub configuration file, and a source/app.d source tree.

Notice that there are two configuration file formats available. JSON is a commonly-known format, and SDL (SDLang) is a clean, minimalist format. Both offer equivalent functionality (though unlike JSON, SDLang allows comments); use whichever you prefer.

The following configuration file is generated:

	"name": "myproject",
	"authors": [
		"My Name"
	"description": "My first project",
	"copyright": "Copyright © 2017, imadev",
	"license": "Boost"
name "myproject"
description "My first project"
authors "My Name"
copyright "Copyright © 2017, imadev"
license "Boost"

For more information and help with configuring your builds, see the documentation for JSON and SDLang. DUB is smart and will provide sane defaults, but you can override almost anything.

Execute dub build to build your project, dub run to build and run it, or dub test to build and run unit tests. The last line below is the output of the default application.

$ dub run
Performing "debug" build using dmd for x86.
myproject ~master: building configuration "application"...
Running ./myproject.exe
Edit source/app.d to start your project.

See the command line interface documentation, or run dub --help and dub <command> --help for more information.

Adding a dependency

When you find a package to use from the DUB registry, add it to the dependency list in your DUB configuration file by running dub add <packageName>.

The DUB registry uses git tags to determine application versioning and DUB's dependency management is designed to work best according to SemVer rules. Please follow the rules of the SemVer specification for all packages you list on the registry. See the package documentation for more information on dependency version specification.

You can publish packages to the registry here.

Building a third-party project

You can easily fetch and build third-party projects published to the dub registry via the dub fetch <package name> command.

To get the package, run dub fetch <package name> to download the package and install it in your user build directory. dub run <package name> can then be used to build and execute the package. dub fetch --cache=local <package name> will extract the package into a subfolder of your current working directory.

Advanced usage

For more advanced feature, like single-file packages and managing local packages, please see the advanced usage guide.