← Back to list

Discovering DUB — Dlang’s Package Manager

When I first started exploring DLang, one of the things that intrigued me most was how its ecosystem and toolchain compared to Python. For…

nlhnt · 2024-10-01 16:01 · 1 claps · 2.2 min read
#cargo #rust #dlang #python #poetry
Open on Medium ↗
Wiki topics: GEN · Genomics & Sequencing LIT · Literature & Writing ✍️ · Writing & Creative

Discovering DUB — Dlang’s Package Manager

When I first started exploring DLang, one of the things that intrigued me most was how its ecosystem and toolchain compared to Python. For those who do not know (most, if not all, of you) I do Python for a living.

After years of working with Python and its ecosystem, I’ve had experienced my fair share of dependency management adventures. You’ve probably heard about pip, poetry, pipx, pyenv, venv, conda/mamba and other tools Python uses to isolate packages in virtualenvironments. Maybe it’s got to do with how Python is just (in some way) elevated-C and for those who don’t know dependency management for C or C++ isn’t as streamlined as it is in Rust or Java/Kotlin or dotnet ecosystem. The tools are just as fractured as they’re in Python (for many reasons). There’s CMake (that can fetch lol), Conan, Hunter, vcpkg to name a few and none of these are “standard”.

Anyway if you ever try the D(lang), you’ll quickly find yourself introduced to DUB, the tool that’s closest equivalent would be (in my opinion) Rust’s own cargo. It’s easy to install and is usually available in your systems package manager. For Windows users: it’s available as a separate install , or you can fetch it using Scoop or Chocolatey. If you’re using GNU/Linux or MacOS you probably don’t really need no introduction to apt/dnf/brew/pacman/emerge.

After going through the installation you can check out the version using the following command.

dub --version
# Output example: DUB version 1.36.0, built on Feb  2 2024

Mars Exploration, DALL-E 2024–10–01

Mars Exploration, DALL-E 2024–10–01

Quick Hello World

Let’s look at a quick “Hello World” example. Run the initialization command found below.

dub init hello_world

You will be asked for a few simple prompts:

  • what’s the name of the project,
  • short project’s description,
  • who’s the author,
  • which format do you prefer to store your project settings in: SDL/JSON,
  • what license would you like to use for your project,
  • copyright string.

After this dub will automatically generate a few simple directories and app’s initial source code for you. In our case we’ll get the most basic template, a “Hello World” program:

// source/app.d
import std.stdio;

void main()
{
 writeln("Edit source/app.d to start your project.");
}

To run the code cd (change directory) into your new projects directory, afterwards use the command. You should immediately see the message “Edit source/app.d to start your project.”

dub run

Managing Dependencies with DUB

We’ve now seen how to use dub to initialize a project. How do we manage the dependencies?

Using our previous example, let’s add a ddbc depdendency, it’s a development library one can use to manage, among others, a sqlite3 database with Dlang. To do that we simply need to run the command:

dub add ddbc

Notice the changes to dub.json (or dub.sdl) in the project directory:

// ./dub.json
{
 "authors": [
  "xyz"
 ],
 "copyright": "Copyright © 2024, xyz",
 "dependencies": {
  "ddbc": "~>0.6.0"
 },
 "description": "A minimal D application.",
 "license": "proprietary",
 "name": "hello_world"
}

// ./dub.sdl
name "hello_world"
description "A minimal D application."
authors "xyz"
copyright "xyz"
license "proprietary"
dependency "ddbc" version="~>0.6.0"

With dub you can manage your project directory structure, your dependencies and where your artifacts should be stored. I suggest reading up more at https://dub.pm/link-upgrades/


메타데이터
post_id
581ee7fe9a8b
slug
discovering-dub-dlangs-package-manager-581ee7fe9a8b
url
https://medium.com/@nlhnt/discovering-dub-dlangs-package-manager-581ee7fe9a8b
canonical_url
https://medium.com/@nlhnt/discovering-dub-dlangs-package-manager-581ee7fe9a8b
author_url
https://medium.com/@nlhnt
status
ok
fetched_at
2026-07-22 16:12:32