Devlog

Gleam [gh|core] is a recent addition to the BEAM ecosystem (see [Erlang] [Elixir] [Hex]). Being FLOSS from the beginning, maintained by nice, friendly people, and not being afraid to be immediately prescriptivist about its tooling, it should make for hopefully a gentle experience. Recently spiked in popularity after its v1 release, especially in the land of “Streamer Driven Development” [@t3dotgg] [@ThePrimeTimeagen], it’s the new hype. This project does not yet have an implementation from the BEAM family. I figured I’d eventually think about maybe considering doing it in Elixir, which I’ve heard good things about, but it’d be fun to battle-test gleam’s tools.

Setup Environment / Tools

“Install Gleam”

Funnily enough, the gleam home page doesn’t link directly to downloads. The first big button is Try Gleam [1], and it’s good to see a fancy in-browser tour, but I am surprised that there is still yet to be a prominent “download here” button. The top panel though links the the docs, and the third link in here is where we see Installing Gleam. There are three parts to this. We’ll be setting it up in Ubuntu WSL and Windows.

Install “Gleam”

First, it will have us go to the releases page, unless you want to use one of the package managers it’s available in. But there is no apt install of it, so to the release page we go. It’s not written anywhere there I can see, but we can put together;

VERSION=1.0.0 curl -s -L https://github.com/gleam-lang/gleam/releases/download/v$VERSION/gleam-v$VERSION-x86_64-unknown-linux-musl.tar.gz | tar xvz -C /tmp && mv /tmp/gleam ~/.local/bin/gleam

And we can install the windows side manually. I’m surprised there isn’t an installer yet, at least, because there’re smaller products that have installers. But that’s not an issue. And it’s probably expected the users will know how to set their paths / manage multiple installs.

Install Erlang

The gleam site recommends the “Erlang solutions website”, but surely Download Erlang/OTP is good as well? We can sudo apt install erlang and accept the half a Gb install, and download and run the windows installer. Windows side installed fine, 14.2.3, but the WSL side required a sudo apt --fix-broken install followed by another sudo apt install erlang, and now it’s on 10.6.4. It turns out later, that for rebar3, they “support the 3 latest major releases of erlang”, and the number that comes back for erl -version is not the version of erlang, which can elsewise be obtained by running erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell which shows us that on Windows we have version 26, and on WSL version 22. To update our WSL version we can;

curl -L https://binaries2.erlang-solutions.com/ubuntu/pool/contrib/e/esl-erlang/esl-erlang_25.0-1~ubuntu~focal_amd64.deb -o /tmp/esl-erlang_25.0-1.deb && sudo dpkg -i /tmp/esl-erlang_25.0-1.deb && rm /tmp/esl-erlang_25.0-1.deb
# But it needs sudo dpkg --auto-deconfigure -i /tmp/esl-erlang_25.0-1.deb, which then asks for;
sudo apt --fix-broken install && sudo apt autoremove -y
# And then it also needs manual dependencies
sudo apt install libncurses5 libsctp1
# Which once again wants a
sudo apt --fix-broken install
# Which asks to confirm to install libncurses5 libsctp1 libtinfo5, and NOW we can install the deb pkg.
# At least `rebar3 local install` works without any further complaints after fighting the erlang installation.

Install Rebar

The gleam page simply says to follow the rebar page. (Also see gh:rebar3).

curl -L https://s3.amazonaws.com/rebar3/rebar3 -o ~/.local/bin/rebar3 && chmod +x ~/.local/bin/rebar3 && rebar3 local install

Yet, although the rebar3 page funnily enough makes a point of driving home that it should just work with any installed erlang, trying to run it on the version of erlang installed by apt on ubuntu 20 yields an;

escript: exception error: undefined function rebar3:main/1
  in function  escript:run/2 (escript.erl, line 758)
  in call from escript:start/1 (escript.erl, line 277)
  in call from init:start_em/1
  in call from init:do_boot/3
=ERROR REPORT==== 19-Mar-2024::23:33:00.202362 ===
beam/beam_load.c(1876): Error loading module rebar3:
  This BEAM file was compiled for a later version of the run-time system than 22.
  To fix this, please recompile this module with an 22 compiler.
  (Use of opcode 172; this emulator supports only up to 168.)

And on windows, adding the rebar3.cmd file adjacent to the rebar3 with the contents it recommends yields a ===> Sorry, this feature is not yet available on Windows.. So I guess we need to just use the file and the cmd script on Windows, and try updating Erlang in Ubuntu. The latest version that Erlang Solutions provides for Ubuntu is 25. And after fighting the upgrade to Erlang version 25, rebar3 local install works as expected.

Install Editor Plugin

A quick search on the vsc marketplace yields an official VS Code Plugin.

“Writing Gleam”

Writing Gleam is an example of how to create a new gleam project; gleam new <project-name>. We’ll run gleam new collatz, and mesh together what it produces with here.

Packaging for Hex

We’ll need to take a look at gleam.toml config, gleam’s cli, Hex Sign up, Hex Publishing a package, and HexDocs. Signing up at Hex Sign up is very simple. After verifying our email, it’s a good idea to setup 2fa. We can publish packages with gleam publish, which at the moment requires HEXPM_USER (Hex username) and HEXPM_PASS (Hex password).

Search Document