JavaScript Solutions, Competitive programming in JavaScript, MCQ in JS

Sunday, 9 September 2018

Installation & Introduction to Crystal Language

Source: Wikipedia

Today, I have started exploring new programming language called Crystal.

Why Crystal Language:

  • Speed: Crystal is compiled language based on LLVM framework so it directly gets executed on runtime.
  • Syntax: As Crystal lang tagline suggest Fast As Slick as Ruby, Crystal uses ruby language like syntax to write code.
  • Statically Type check:   Crystal is statically type checked language so any type of errors will be shown or caught on compile time rather than fail at runtime. 
  • Clean: Crystal has built-in type inference, so most type annotations are unneeded.
  • Null Reference Check:  Compiler automatically checks for null references in compile time only.
  • Macros: We can create and use macros so it's easy to use. your dynamic method definition could be replaced with a compile-time macro in as many lines of code.
  • Green Threads: Crystal uses green threads, called fibers, to achieve concurrency. Fibers communicate with each other using channels.

Who and When Crystal language developed?

As per Wikipedia crystal langauge developed by Ary Borenszweig, Juan Wajnerman, Brian Cardiff and some contributors.
Work on Crystal langauge began in 2011, and its first official release was in June 2014

So we got some basic details about Crystal language so let's proceed with installing it on our local machine.

Installation of Crystal Langauge:

Crystal on Ubuntu System:

The following packages are not required, but recommended for using the respective features in the standard library:
sudo apt install libssl-dev      # for using OpenSSL
sudo apt install libxml2-dev     # for using XML
sudo apt install libyaml-dev     # for using YAML
sudo apt install libgmp-dev      # for using Big numbers
sudo apt install libreadline-dev # for using Readline
Now add the repository to your APT configuration.

curl -sSL | sudo bash
That will add the signing key and the repository configuration, you can do this manually as well.

Now install Crystal repository.

sudo apt install crystal

And here you are done with your installation is done for Ubuntu system,
Now we will write Hello World program in Crystal Language.

Hello World program in Crystal Language:

  • Now Create a file called
  • Write the following code in this file.
puts "Hello World"
  • Now save it and open the terminal on the same location where file saved
  • Run following command:
crystaldemo$ crystal

It should so following output.

$ crystal
Hello World

And its done you are awesome you have completed your hello world program in crystal language.

Thanks for reading, please comment if you find any issues with it.

No comments:

Post a Comment