Fast as C, slick as Ruby — https://crystal-lang.org/

Crystal is a statically-typed, general-purpose, compiled, fast, programming language. The initial compiler was written in Ruby but was later written in Crystal which means it is self-hosted. A language that is self-hosting means that it can create new versions of itself. Basically, this means that you can write a Crystal-compiler in Crystal. So once the Ruby-version of the compiler was at a point at which it could compile a compiler, written in Crystal, that’s what the developers did. So now Crystal is written in itself. Anyways, let’s continue.

This article was inspired by and should serve as an addition to the Ubuntu installation guide in the official Crystal Documentation. There is more information there that may be important. If you run into issues, feel free to reach out!

If you want to play around with this interesting language, you can easily do so by visiting the web-hosted compiler that can be accessed through the official Crystal website.

There, you would be able to play around and write some simple (or even complex) applications and then have the browser spit back what was likely compiled on a server somewhere the moment you clicked “Compile and run code”. This is cool but for you to start writing larger, multi-file applications, you will likely want to install it on your development machine. It’s extremely simple to do this on Ubuntu, as the community of contributors have determined to maintain up-to-date repository packages.

Follow the steps below and you should have no issue getting the Crystal compiler running on your machine, assuming that you run Ubuntu.

Make sure that your version of Ubuntu is up to date

The latest LTS version of Ubuntu is ‘18.04’. You may be running an older version, or even ‘18.10’. To check your version, open your terminal of choice and run the following.

lsb_release -a

The ‘lsb_release’ command prints general LSB(Linux Standard Base) and Distribution information. When you run that command, you will probably see something like this…

Distributor ID: Ubuntu

Description: Ubuntu 18.04.1 LTS

Release: 18.04

Codename: bionic

For more information on ‘lsb_release’, consider reading the following documentation.

Upgrade if you are running a version older than 18.04

Upgrading is fairly simple using the ‘do-release-upgrade’ utility. First we want to make sure that is installed and then we will run the command. This utility is similar to ‘dist-upgrade’ but according to the documentation, it handles configuration changes that may happen. So that’s a plus! The ‘do-release-upgrade’ utility can be found in the ‘update-manager-core’ package. To use the utility, we will need to make sure that is installed.

sudo apt-get install update-manager-core

sudo do-release-upgrade

You will likely need to press ‘y’ since it is a larger download.

Now, add the repository to your APT configuration

curl -sSL https://dist.crystal-lang.org/apt/setup.sh | sudo bash

I encourage you to download that script and check it out, before you run it. You can do that easily in your terminal by running the following.

It will look something like this…

#!/usr/bin/env bash apt-key adv — keyserver keys.gnupg.net — recv-keys 09617FD37CC06B54

/etc/apt/sources.list.d/crystal.list echo “deb https://dist.crystal-lang.org/apt crystal main” >/etc/apt/sources.list.d/crystal.list apt-get update

Install Crystal

The hard part is done. Now it’s time to install the compiler and other tools that are included with the package.

sudo apt-get install crystal

To make sure you did everything correctly, simple run the following.

crystal --help

It will print something like…

Usage: crystal [command] [switches] [program file] [ — ] [arguments] Command:

init generate a new project

build build an executable

docs generate documentation

env print Crystal environment information

eval eval code from args or standard input

play starts crystal playground server

run (default) build and run program

spec build and run specs (in spec directory)

tool run a tool

help, — help, -h show this help

version, — version, -v show version

You can run the following command to check which version was installed.

crystal --version

Now you’re all set! Have fun and enjoy using Crystal. I strongly advise checking out the following links if you’d like to learn more or show your support for the project. I plan to release more articles with my experiences using this language, in the future, as well as updates on my projects that use it. Thanks for reading!