How to compile last version of Crystal Lang on Debian 8

If you are a developer, you could be intersted by Crystal Lang : it takes up the greater part of the syntax of ruby, but makes it possible to compile the code and to have better performances. Here is the step-by-step compilation tutorial on Debian 8.

Get Crystal

To compile Crystal, we need first to download Crystal sources. We will use git. On debian systems, open a console, and install git with : sudo apt-get install git. Go to you Home folder : cd.

Then, in your console, type :

git clone https://github.com/crystal-lang/crystal

Verify that crystal is cloned with ls -l |grep crystal

Install dependencies

You need LLVM to compile Crystal. Install LLVM with this command : sudo apt-get install llvm .

You also need the Boehm-Demers-Weiser conservative C/C++ Garbage Collector. You need to clone and compile it :

git clone https://github.com/ivmai/bdwgc.git
cd bdwgc
git clone https://github.com/ivmai/libatomic_ops.git
autoreconf -vif
automake --add-missing
./configure
make
make check
sudo make install

Compile Crystal

Once dependencies are installed, let's compile Crystall : go to crystal dir : cd && cd crystal and type make. If you get this message : "Could not locate llvm-config, make sure it is installed and in your PATH, or set LLVM_CONFIG", LLVM is not correctly installed.

If compilation is ok, the fresh Crystal should be here : .buid/crystal

Test the compiler

To test the Crystal compiler, go to your home folder : cd. Create a folder test : mkdir test, and copy the Cystal compiler in it :

cp ./crystal/.build/crystal test/.

Go to you test folder : cd test, and create a file named hello.cr : touch hello.cr. Now, let's make a simple "Hello World" program : echo 'puts "Hello World\n"' > hello.cr

We can run test.cr : ./crystal hello.cr

If all is ok, it should output Hello World.

Now, let's compile this : ./crystal build hello.cr. You should have a new file name hello. Run this program : ./hello. You should get Hello World to.

You can either compile a program with optimization options :

./crystal build --release hello.cr

Problems

If you got problems during compilation, don't hesitate to contact us via comments, we will help you.