You may install d2 through any of the following methods.
The recommended and easiest way to install is with our install script, which will detect the OS and architecture you're on and use the best method:
# With --dry-run the install script will print the commands it will use
# to install without actually installing so you know what it's going to do.
curl -fsSL https://d2lang.com/install.sh | sh -s -- --dry-run
# If things look good, install for real.
curl -fsSL https://d2lang.com/install.sh | sh -s --For help on the terminal run, including the supported package managers and detection methods:
curl -fsSL https://d2lang.com/install.sh | sh -s -- --helpThe install script is not the most secure way to install d2. We recommend that if
possible, you use your OS's package manager directly or install from source with go as
described below.
But this does not mean the install script is insecure. There is no major flaw that the install script is more vulnerable to than any other method of manual installation. The most secure installation method involves a second independent entity, i.e your OS package repos or Go's proxy server.
We're careful shell programmers and are aware of the many footguns of the Unix shell. Our
script was written carefully and with detail. For example, it is not vulnerable to partial
execution and the entire script runs with set -eu and very meticulous quoting.
It follows the XDG standards, installs d2 properly into a Unix hierarchy path
(/usr/local unless /usr/local requires sudo in which case ~/.local is used) and
allows for easy uninstall. You can easily adjust the used path with --prefix.
Some other niceties are that it'll tell you if you need to adjust $PATH or $MANPATH to
access d2 and its manpages. For releases that bundle TALA, select it with
d2 --layout=tala; run d2 layout to check the installed engines.
This installer installs only D2 and rejects the obsolete --tala option before
installation. Omit that option when installing D2. Older D2 releases require the
separate plugin available from the legacy TALA releases.
You can install a specific version of d2 with --version. Run the script with
--help for detailed docs on its options and features.
If you're still concerned, remember you can run with --dry-run to avoid writing anything.
The standalone installer includes the SHA-256 of each supported archive starting with v0.8.2. During release review, D2 checks the signed checksum manifest against the release workflow, tag, and source commit. Your installer checks the downloaded or cached archive against that reviewed digest before extraction using your system's SHA-256 tool. Upgrades and forced reinstalls run the archive's installation recipe in a temporary prefix. The installer replaces the executable after the new release tree and manpage are in place. These steps require no additional download.
Pass --verify-provenance to check the signed build provenance on your machine as well.
The installer also performs this check automatically when installing a new release that
postdates its embedded digests. It verifies the repository, workflow, tag, and exact archive
name and digest. This check uses GitHub CLI (gh) 2.102.0 or newer from your PATH or a
temporary, checksum-pinned download. Neither path requires a GitHub account or token.
An explicitly requested historical release through v0.7.1 uses GitHub's SHA-256 digest when available and prints a warning. Strict verification rejects these unsigned releases.
You can also verify a downloaded archive yourself. For example:
gh attestation verify d2-v0.9.0-linux-amd64.tar.gz --repo d2lang/d2 \
--signer-workflow d2lang/d2/.github/workflows/release-archives.yml \
--source-ref refs/tags/v0.9.0D2 binaries built with Go 1.27 require macOS 13 Ventura or newer.
If you're on macOS, you can install with brew.
brew install d2The install script above does this automatically if you have
brewinstalled and are running it on macOS.
You can also install from source with:
brew install d2 --HEADThe following distributions have packages for d2:
All supported platforms:
xbps-install d2We publish standalone release archives for every release on Github.
Here's a minimal example script that downloads a standalone release, extracts it into the current directory and then installs it. Adjust VERSION, OS, and ARCH as needed.
VERSION=v0.0.13 OS=macos ARCH=amd64 curl -fsSLO \
"https://github.com/d2lang/d2/releases/download/$VERSION/d2-$VERSION-$OS-$ARCH.tar.gz" \
&& tar -xzf "d2-$VERSION-$OS-$ARCH.tar.gz" \
&& make -sC "d2-$VERSION" installTo uninstall:
VERSION=v0.0.13 make -sC "d2-$VERSION" uninstallYou can also manually download the .tar.gz release for your OS/ARCH combination and then
run the following inside the extracted directory to install:
make installRun the following to uninstall:
make uninstallYou can control the Unix hierarchy installation path with PREFIX=. For example:
# Install under ~/.local.
# Binaries will be at ~/.local/bin
# And manpages will be under ~/.local/share/man
# And supporting data like icons and fonts at ~/.local/share/d2
make install PREFIX=$HOME/.localThe install script places the standalone release into $PREFIX/lib/d2/d2-<version>
and we recommend doing the same with manually installed releases so that you
know where the release directory is for easy uninstall.
You can always install from source:
go install github.com/d2lang/d2@latestD2 requires Go 1.27.4 or newer.
To install a release from source clone the repository and then:
./ci/release/build.sh --install
# To uninstall:
# ./ci/release/build.sh --uninstallInstalling a real release will also install manpages and in the future other assets like
fonts and icons. Furthermore, when installing a non versioned commit, installing a release
will ensure that d2 --version works correctly by embedding the commit hash into the d2
binary.
Use the compiler version declared in go.mod when building release archives.
We have prebuilt releases of d2 available for Windows via .msi installers. The installer
will add the d2 binary to your $PATH so that you can execute d2 in cmd.exe or
pwsh.exe.
We also have release archives for Windows structured in the same way as our Unix releases for use with MSYS2.
See MSYS2 or Git Bash (Git Bash is based on MSYS2).
MSYS2 provides a unix style shell environment that is native to Windows (unlike
Cygwin). MSYS2 allows install.sh to work, enables automatic
installation of our standalone releases via make install and makes the manpage
accessible via man d2.
The MSYS2 terminal also enables d2 to display colors like in the above screenshot.
In addition, all of our development and CI scripts work under MSYS2 whereas they do not under plain Windows.
d2 works perfectly under WSL
aka Windows Subsystem for Linux if that's what you prefer. Installation is just like any
other Linux system.
The following are community-managed Windows releases of d2 on popular package managers
scoop install main/d2choco install d2The canonical image is d2lang/d2.
terrastruct/d2 remains available as a maintained compatibility mirror for existing
installations, but new usage should use d2lang/d2.
We publish amd64 and arm64 images based on debian:latest for each release.
Example usage:
echo 'x -> y' >helloworld.d2
docker run --rm -it -u "$(id -u):$(id -g)" -v "$PWD:/home/debian/src" \
-p 127.0.0.1:8080:8080 d2lang/d2:v0.1.2 --watch helloworld.d2
# Visit http://127.0.0.1:8080- rpm and deb packages
- with repositories and standalone
- homebrew core
