Executable wont run on computer without libraries installed

You can build statically linked programs in Crystal but now it only works on Alpine Linux.

You can install Docker for Mac and use https://hub.docker.com/r/jrei/crystal-alpine for building statically linked apps.

Basically in addition to Crystal itself you install all required libraries in Docker https://github.com/j8r/dockerfiles/blob/master/crystal-alpine/Dockerfile#L6-L22

Then use crystal build --static ... to build statically linked application. After that you can copy your single binary to another Docker container with Alpine Linux but without Crystal and any mentioned libraries installed and it will work.

UPDATE:
And you’ll also need this workaround https://github.com/j8r/dockerfiles/tree/master/crystal-alpine#usage

2 Likes