Not the most ideal way to install something on OpenBSD for various reasons. It will be great if there were packages already built for Crystal.
Install bash: doas pkg_add bash
OpenBSD comes with a default shell ksh
. Crystal needs bash to run.
$ crystal
env: bash: No such file or directory
Download the OpenBSD tarball from https://github.com/crystal-lang/crystal/releases. The latest version of Crystal available for OpenBSD is 0.19.4.
Extract it to where you store user downloaded binaries e.g. /usr/local
or /opt
Link the binary to your path.
$ ln -sf /usr/local/crystal/bin/crystal /usr/local/bin/crystal
Try running crystal to get the version:
$ crystal -v
Crystal 0.19.4 [7f82f79] (2016-10-07)
Create a Crystal program and run it.
/home/user/fib.cr
def fibonacci(n)
return n if n <= 1
fibonacci(n - 1) + fibonacci(n - 2)
end
puts fibonacci 40
$ vim fib.cr
$ crystal build --release fib.cr
$ time ./fib
102334155
0m00.94s real 0m00.81s user 0m00.01s system
It runs pretty fast on my OpenBSD server. OpenBSD is not particularly fast versus other operating systems, choosing a fast programming language helps speed things up.
Published on 4 Dec 2016 by Stanley Tan