Setup Vibe.d on Ubuntu 14.04

Published on: Sun, Nov 23, 2014 at 10:51 am EST
Programming Ubuntu

Vibe.d is a web framework written in D, for D programmers to develop web and network applications. One thing that Vibe.d is known for is the ability to develop and deploy servers. In this article, we will show you how to setup Vibe.d on Ubuntu 14.04 x64. This should work on Ubuntu 12.04 and 14.10 also, but results may vary.

Requirements

  • Vultr VPS with Ubuntu 14.04 x64.
  • Basic Knowledge of D.
  • Have DMD, LDC, or GDC installed (DMD is recommended).
  • Have DUB installed.

Install Libraries

Before getting started, you will need to install a few dependencies so that your project will build:

apt-get install libssl-dev libevent-dev

Create Project

Using dub, create a project by running the following command in a directory:

dub init server vibe.d

What this will do is create a new project with the Vibe.d template built in to dub.

Update dub.json

Like package.json for NPM (Node.js), dub.json stores information about your application that will be used for building or deploying. Inside your dub.json file, you may see something similar to:

{
        "name": "server",
        "description": "A simple vibe.d server application.",
        "copyright": "Copyright © 2014, root",
        "authors": ["root"],
        "dependencies": {
                "vibe-d": "~>0.7.19"
        },
        "versions": ["VibeDefaultMain"]
}

If you want, you can change the name, description, copyright, author, and so forth. For now, we are going to focus on the data in the dependencies section. Change the current version from 0.7.19 to 0.7.21. This will ensure you are using the latest version of Vibe.d. Once you change the version and save the file, then you can proceed to the next step.

Update source/app.d

Inside your source/app.d file, you should see a line that shows:

settings.bindAddresses = ["::1", "127.0.0.1"];

This sets the address of which the server will listen on. In this case, the loopback addresses ::1 (IPv6) and 127.0.0.1 (IPv4) are used. You have some options here. You can change the addresses to a public IP available on your Vultr VPS, or you can comment out that line to listen on any available address. It is purely your choice, but for now change 127.0.0.1 to 0.0.0.0 to prevent any confusion. This will make your application listen on any IP assigned to the server.

Build Project

Run the following command to build your application:

dub build

This will go through the process of fetching your dependencies, building them, and then building your application. Once complete (assuming that there are no errors), you should have a file called server in the root of your directory. Run it by doing ./server and it will show the following:

Listening for HTTP requests on ::1:8080
Listening for HTTP requests on 0.0.0.0:8080
Please open http://127.0.0.1:8080/ in your browser.

If you do not see a failure message, proceed to your web browser and enter the IP address as well as the port. For example: http://0.0.0.0:8080 with 0.0.0.0 changed accordingly.

If you see Hello, World! in your browser, then you have successfully setup Vibe.d on your server.

Understanding Vibe.d

Server Development

Vibe.d came a long way, which provided a way for developers to develop server-based applications. This includes web server applications, which Vibe.d supports natively.

Diet Templates

When it comes to web development, diet templates are based completely around Jade, except that diet templates compile directly into your application. This uses D inside your project (Much like how you can use embedded Javascript inside Jade). Using diet templates adds flexibility to the content that your application displays on the web browser.

Performance

When it comes to performance, Vibe.d has shown to scale up to a very high level. With its asynchronous I/O, it creates a memory overhead that is much lower than what you would normally find on applications made with Node.js, Java, and Python. Only a single hardware thread is needed to handle the number of concurrent operations.

Want to contribute ?

You could earn up to $300 by adding new articles