The vibe.d framework is written in the D programming language. To get started, you need a D compiler and the DUB package manager. You also need to install
libevent, which are used by vibe.d.
There are three major D compilers available, as follows:
You can use any of these compilers to develop with the vibe.d framework. However, the installation instructions are very different. In this book, only the DMD compiler is used.
A recommended setup is to use the DMD compiler during development and one of the other compilers to produce the final highly optimized binary.
The easiest way to install DMD on Ubuntu and Debian is to use the D APT repository provided by Jordi Sayol. The website of this project is located at http://d-apt.sourceforge.net/. The steps to install DMD and DUB are as follows:
Open a terminal and type the following in order to add the repository sources:
$ sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
Then, you need to update the list of packages:
$ sudo apt-get update
This command complains that the public key for the d-apt repository could not be verified. The displayed fingerprint is
EBCF975E5BA24D5E. Allow an unauthenticated install of
d-aptand update the list of packages again:
$ sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring $ sudo apt-get update
$ sudo apt-get install -y dmd-bin $ sudo apt-get install -y dub
Lastly, you need to install
$ sudo apt-get install -y libssl-dev libevent-dev
On Fedora, you use the pre-built compiler binary from the
dlang.org website. There is no package for the DUB package manager therefore, you must built this tool from the source. Refer to http://dlang.org/download.html and download the Fedora package of the DMD compiler. The available version at the time of writing this book is 2.068.2. You may need to change the version number when a new version of the compiler is released. The instructions are given for Fedora 22 or later. If you use Fedora 21 or earlier, then replace the
dnf command with
yum. The steps to install the DMD complier are as follows:
dmd, type in a terminal:
$ sudo dnf install –y dmd-2.068.2-0.fedora.x86_64.rpm
Install the required
libeventlibraries. You also need to install the development package of
libcurlthat is used to compile
$ sudo dnf install –y openssl-devel libevent-devel libcurl-devel
After that, go to http://code.dlang.org/download and download source tarball of DUB. The current version number is 0.9.24. Again, you need to change the version number if a newer version is available. To compile and install, just type the following:
$ tar xvzf dub-0.9.24.tar.gz $ cd dub-0.9.24 $ ./build.sh $ sudo cp bin/dub /usr/local/bin
If you get an error message that you are not in the list of sudoers, then you need to change the type of your user to administrator. Open system settings and click on Users. Click on the Unlock button to unlock the window and change the account type to Administrator. Now you can use the
To install the D compiler and the DUB package manager, you can use the Homebrew package manager (http://brew.sh/):
Open a terminal and first update the formulae:
$ brew update
Now install the D compiler:
$ brew install dmd
Next, you will install the DUB package manger:
$ brew install dub
Lastly, you need to install
$ brew install openssl libevent
On Windows, you will simply use the pre-built binaries from the
dlang.org website. Go to http://dlang.org/download.html and download the Windows EXE file of the DMD compiler. Double-click on the downloaded file in order to start the installer and then follow the instructions on the screen. The D compiler is now ready to use.
DUB is installed in a similar way. Go to http://code.dlang.org/download and download the installer for Windows. Double-click on the downloaded file to start the installer and then follow the instructions on the screen as done previously.
You can also build the applications from source. For some systems, (for example, FreeBSD, Solaris x86, and Linux on non-Intel platforms) this is the only way to install the software. The following are the instructions for a Portable Operating System Interface (POSIX) for a Unix system.
At the time when this book was written, the compiler itself was translated from C++ to D. Version 2.068 is the first one that requires a D compiler for bootstrap. Therefore, you need to install version 2.067.1 before you can install the current version of the compiler.
At build time, you need the GNU C/C++ compiler (gcc/g++) and GNU make (gmake). Using another compiler or make tool may work but is not well tested. For Phobos (the D standard library), you need to have
libcurl installed. If your distribution does not provide
libcurl, then you can find the source and install the instructions at the http://curl.haxx.se/libcurl/ website.
The easiest way to build DMD from source is using the GitHub repository. First, you build version 2.067.1. This creates a D compiler that you will then use to compile the final version that you want to install, as follows:
Change to your working directory. Then, check the sources from GitHub:
$ for i in dmd druntime phobos; do git clone https://github.com/D-Programming-Language/$i.git; done
Now, check out version 2.067.1, as follows:
$ for i in dmd druntime phobos; do (cd $i && git checkout v2.067.1); done
Compile the D compiler and install it to
/tmp/dmdas shown in the following code. The CPU model (32 bit or 64 bit) is automatically determined by the makefile. If this fails, you can add
MODEL=32(for 32 bit) or
MODEL=64(for 64 bit) to the
$ for i in dmd druntime phobos; do make -C $i -f posix.mak install INSTALL_DIR=/tmp/dmd done
Now clean the directories:
$ for i in dmd druntime phobos; do make -C $i -f posix.mak clean done
Next, check out the version of the compiler that you prefer using. Currently, it is 2.068.2:
$ for i in dmd druntime phobos; do git checkout v2.068.2 done
Then, you can compile and install the version of the compiler. You need to specify the previously installed compiler. The binary is found in sub-folders specifying the operating system and CPU model, for example,
$ make -C dmd -f posix.mak HOST_DC=/tmp/dmd/linux/bin64/dmd install INSTALL_DIR=~/dmdss $ make -C druntime -f posix.mak install INSTALL_DIR=~/dmd $ make -C phobos -f posix.mak install INSTALL_DIR=~/dmd
The last step is to add the compiler to your
PATHenvironment variable. The syntax depends on the shell you use. For bash, you run:
$ export PATH=~/dmd:$PATH
Building the DMD compiler on Windows differs from these generic instructions as you need the Digital Mars C/C++ compiler. I recommend using the binary download for Windows. You can find detailed build instructions for all supported systems in the wiki at http://wiki.dlang.org/Building_DMD.
The DUB package manager is written in D. Go to http://code.dlang.org/download and download the source code archive. Under the file, change the current directory of your shell to the
dub-0.9.24 folder and build the application with the following commands. You may need to replace the current version number 0.9.24 with the version you downloaded.
$ tar xvzf dub-0.9.24.tar.gz $ cd dub-0.9.24 $ ./build.sh
You'll find the binary in the
bin folder. You can add this folder to your
PATH variable or copy the file to a standard folder, for example,
$ cp bin/dub /usr/local/bin
You should see the help text provided by the compiler. The version number should be the same as the version you have downloaded.
On Linux and other POSIX systems, you can also check whether the additional libraries are installed. Run the following command:
$ touch empty.d && dmd -main empty.d -L-lssl -L-levent && ./empty
It should produce no error messages.
An error, most likely, indicates that the libevent library or the OpenSSL library is not installed on your system. You should check the install instructions that are mentioned previously for common systems. If your system is not mentioned, then you should consult the manual of your OS to know how to install additional software. If your OS does not provide these libraries, then you have to install them from source. You can find install instructions and the source archive for libevent at http://libevent.org/. The https://openssl.org/ OpenSSL site provides install instructions and the source archive. You can check your DUB installation simply by running the following command:
$ dub help
This prints the help text from DUB. The version number should be the same as the version that you have downloaded.