Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Forums
  - IRC
  - Community Discord
  - Wiki
  - GitHub
  - Issues
  - Get involved
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

# Install.sh script

## Introduction

The dlang.org/install.sh script is the official D compiler version manager. It supports DMD, GDC and LDC on FreeBSD, Linux, macOS and Windows (although not every combination is available). It provides a convenient way to fetch and install a D compiler, and switch between installed versions, without requiring administrative privileges. Its features include:

- Maintaining one or more portable compiler installations in a directory of choice (default ~/dlang on POSIX, %USERPROFILE%/dlang on Windows).
- Maintaining the latest stable version of the D package manager, dub.
- Self-updating via install.sh update.
- Supporting nested activation of compilers. Activating a compiler will set up the relevant environment variables, and offer means to revert the modified variables to their prior values.
- Supporting the Fish shell, in addition to Bash-compatible shells.
- Verifying binary signatures via the D keyring (automatic if gpg is installed)
- For dmd, installation of the following versions is supported:
  - dmd - latest stable version
  - dmd-beta - latest beta version
  - dmd-nightly - the latest nightly release
  - dmd-<version> - specific official release (including beta releases)
  - dmd-branch - experimental compiler branches
- For ldc, installation of the following versions is supported:
  - ldc - latest stable version
  - ldc-beta - latest beta version
  - ldc-latest-ci - latest build version (built on every commit to master by CIs)
  - ldc-<version> - specific official release (including beta releases)
- For gdc, installation of the following versions is supported:
  - gdc - latest stable version, Linux only
- For dub, installation of the following versions is supported:
  - dub - latest stable version
  - dub-<version> - specific official release (including beta releases)
- For all compilers optionally installing a different version to the bundled dub is supported:
  - <compiler>,dub - selected compiler and latest stable DUB version
  - <compiler>,dub-<version> - selected compiler and a specific stable DUB version

### Content

- Downloading the installer

- On FreeBSD, Linux and macOS
- On Windows

- Using Git BASH
- Using MSYS BASH

- Usage

- Installation
- Activation

- On POSIX
- On Windows

- Uninstallation
- Listing available compilers
- Update
- Get compiler executable path

## Downloading the installer

- On FreeBSD, Linux and macOS
- On Windows

- Using Git BASH
- Using MSYS BASH

### Downloading on FreeBSD, Linux and macOS

    mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh

Alternatively, the script can be invoked directly:

    curl https://dlang.org/install.sh | bash -s

In this case the installer makes a copy of itself at ~/dlang/install.sh. If no arguments are provided, the latest DMD compiler will be installed.

### Downloading on Windows

The instructions above work unaltered when using a POSIX-like environment on Windows, such as Cygwin or MSYS2, but then compilers are installed inside that environment. For better integration with a typical Windows development environment, you may follow the instructions below instead, which makes compilers available from the Windows Command Prompt.

    mkdir %USERPROFILE%\dlang
    powershell.exe -Command "wget https://dlang.org/install.sh -OutFile %USERPROFILE%\dlang\install.sh"

The script is interpreted by bash.exe, which comes as part of MSYS2 as well as Git for Windows. The following two sections provide two alternatives for defining %BASH% so that the POSIX-tailored examples further down will work from the Windows command prompt by replacing "~/dlang/install.sh" with "%BASH% %USERPROFILE%\dlang\install.sh". With either one of these alternatives, this will work:

    %BASH% %USERPROFILE%\dlang\install.sh --help

#### Using Git BASH

Download and install Git for Windows to "C:\Program Files\Git" and 7-Zip to "C:\Program Files\7-Zip". 7z.exe needs to be in the PATH:

    set PATH=%PATH%;C:\Program Files\7-Zip
    set BASH="\Program Files\Git\usr\bin\bash.exe"

#### Using MSYS BASH

Follow the installation instructions for MSYS2. We'll assume MSYS2 is now available in C:\msys64, which is the default for the 64-bit installer. This will install the necessary decompression tools:

    C:\msys64\usr\bin\pacman.exe --sync unzip p7zip
    set BASH=C:\msys64\usr\bin\bash.exe

## Usage

    ~/dlang/install.sh [<command>] [<args>]

- Installation
- Activation

- On POSIX
- On Windows

- Uninstallation
- Listing available compilers
- Update
- Get compiler executable path

### Global options

-p --path
  Changes the install location (default ~/dlang on POSIX, %USERPROFILE/dlang on Windows)
-v
  Produces more verbose output
-h
  Displays a help page

### Install

    ~/dlang/install.sh install <compiler>

Download and install a D compiler. By default the latest release of the DMD compiler is selected.

#### Options

-a --activate
  Prints the path to the activate script
dmd|ldc|gdc
  Installs the latest version of a compiler
dmd|ldc|gdc-<version>
  Installs a specific version of a compiler (e.g. dmd-2.071.1, ldc-1.1.0-beta2)
dmd|ldc-beta
  Installs the latest beta version of a compiler
dmd-nightly
  Installs DMD nightly
dmd-2017-02-10
  Installs specific DMD nightly
dub
  Installs the latest version of a dub
dub-<version>
  Installs a specific version of a dub (e.g. dub.1.23.0)
<compiler>
  Installs a version of compiler and a version of dub. All compiler and version strings listed above are supported.

#### Examples

    ~/dlang/install.sh
    ~/dlang/install.sh dmd
    ~/dlang/install.sh install dmd
    ~/dlang/install.sh install dmd-2.071.1
    ~/dlang/install.sh install ldc-1.1.0-beta2
    ~/dlang/install.sh install dmd-beta
    ~/dlang/install.sh install dmd-nightly

By default, the dub binary bundled in the compiler installation will be exposed. Optionally, a different dub version can be installed standalone or as part of the compiler installation:

#### Examples

    ~/dlang/install.sh install dub
    ~/dlang/install.sh install dub-1.22.0
    ~/dlang/install.sh install dmd-2.071.1,dub-1.23.0
    ~/dlang/install.sh install ldc-1.23.0,dub

An installed compiler can be used directly, but the exact path varies between compiler vendors:

    ~/dlang/<installed-dmd-compiler>/bin64/dmd
    ~/dlang/<installed-ldc-compiler>/ldc2

Therefore it is recommended to activate a compiler after installation. For scripting needs the path to compiler executable can be queried with get-path.

### Activate

Once a compiler is installed, it can be activated for the current session. Supplying the -a or --activate option to the install command will print the path to the appropriate activation script: either a shell script or a Windows batch file.

#### In POSIX environments

    ~/dlang/install.sh install <compiler> -a

This will show where to find the activate script (or activate.fish for users of the Fish shell.) The script should be executed in the current shell:

    source ~/dlang/<installed-compiler>/activate

This will set up the PATH, LIBRARY_PATH, LD_LIBRARY_PATH, DMD, DC, and PS1 environment variables. It's also possible to combine this into one command:

    source $(~/dlang/install.sh dmd -a)

The activated compiler can be removed from the current session by restoring the previous environment:

    deactivate

#### On the Windows command line

    %BASH% %USERPROFILE%\dlang\install.sh install <compiler> -a

This will show where to find the activate.bat file. Calling it will change the PATH environment variable, and show how to restore its prior value.

    %USERPROFILE%\dlang\<installed-compiler>\activate.bat

To install and activate %COMPILER% in a batch file, this will do:

    set INSTALL=%BASH% %USERPROFILE%\dlang\install.sh install %COMPILER%
    %INSTALL%
    for /f "usebackq tokens=*" %%a in (%INSTALL% -a) do call %%a

### Get compiler executable path

    ~/dlang/install.sh get-path <compiler>

Returns the path to the selected compiler executable. The command fails if the compiler is not installed locally and --install hasn't been passed.

#### Options

--dmd
  Prints the path to the DMD-alike executable
--dub
  Prints the path to the DUB executable
--install
  Installs the compiler if it is not installed

#### Examples

    $ ~/dlang/install.sh get-path dmd
    /home/user/dlang/dmd-2.094.0/linux/bin64/dmd
    $ ~/dlang/install.sh get-path dmd-2.093.0 --install
    /home/user/dlang/dmd-2.093.0/linux/bin64/dmd
    $ ~/dlang/install.sh get-path ldc-1.23.0
    /home/user/dlang/ldc-1.23.0/bin/ldc2
    $ ~/dlang/install.sh get-path --dmd ldc-1.23.0
    /home/user/dlang/ldc-1.23.0/bin/ldmd2
    $ ~/dlang/install.sh get-path --dub ldc-1.23.0
    /home/user/dlang/ldc-1.23.0/bin/dub
    $ ~/dlang/install.sh get-path --dub dub-1.21.0
    /home/user/dlang/dub-1.21.0/bin/dub
    $ ~/dlang/install.sh get-path --dub ldc-1.23.0,dub-1.21.0
    /home/user/dlang/dub-1.21.0/bin/dub

### Uninstall

Uninstall a D compiler.

    ~/dlang/install.sh uninstall <compiler>

#### Examples

    ~/dlang/install.sh uninstall dmd
    ~/dlang/install.sh uninstall dmd-2.071.1
    ~/dlang/install.sh uninstall ldc-1.1.0-beta2

### List

List all installed D compilers.

    ~/dlang/install.sh list

### Update

Update the installer itself and the keyring.

    ~/dlang/install.sh update

Copyright © 1999-2023 by the D Language Foundation | Page generated by Ddoc on Fri Sep 1 19:45:43 2023