Emacs, scripting and anything text oriented.

Downloading Nim

Kaushal Modi

Download and “installing” Nim using just curl and tar.

Today I saw this toot by user @hyperlinkyourheart regarding installing Nim:

Not a great experience so far though - choosenim is broken on Ubuntu 22.04 based systems ..

.. and that inspired this quick post. I would encourage the user posting that to bring up that issue on the Nim Forum, but here’s a quick stop-gap solution to install Nim using just curl and tar.

  1. Copy and save the below script somewhere, let’s say as ~/scripts/download_nim.sh. Update the nim_install_dir variable in there to your choice. That is set to ${HOME}/nim by default.
    #!/usr/bin/env bash
    # Running this script will download and extract nim installation to ~/nim/${nim_version}.
    # To uninstall nim, just remove the ~/nim directory.
    set -euo pipefail # http://redsymbol.net/articles/unofficial-bash-strict-mode
    mkdir -p "${tmp_dir}"
    cd "${tmp_dir}" || exit
    echo "Downloading nim archive from ${nim_archive_url} .."
    curl -RLs "${nim_archive_url}" -o "nim.tar.xz"
    tar xf nim.tar.xz # Extracts to ${nim_download_dir}.
    if [[ -d "${nim_version_dir}" ]]
        rm -rf "${nim_version_dir}"
    mkdir -p "${nim_version_dir}/doc"
    cd "${nim_version_dir}" || exit
    cp -fP "${nim_download_dir}"/doc/*.css ./doc/. # Required for 'nim doc ..' to work
    cp -rfP "${nim_download_dir}"/bin .
    cp -rfP "${nim_download_dir}"/lib .
    cp -rfP "${nim_download_dir}"/compiler . # Required for 'nimterop' package
    cp -rfP "${nim_download_dir}"/config .
    cd "${nim_install_dir}" || exit
    find . -name "bin" -type l -delete
    ln -fs "${nim_version_dir}"/bin ./bin
    echo "Finished downloading $("${nim_version_dir}"/bin/nim -v | head -n 1)"
    Code Snippet 1: Nim download script
  2. Make the script an executable: chmod +x ~/scripts/download_nim.sh
  3. Run ~/scripts/download_nim.sh.. This will download the nim compiler and its standard libraries (totaling to only 40MB!) to the path set in ${nim_install_dir}.
  4. Make sure that the path in ${nim_install_dir} is added to your PATH.
  5. Run nim --version to check the installation.
    Nim Compiler Version 1.6.6 [Linux: amd64]
    Compiled at 2022-05-05
    Copyright (c) 2006-2021 by Andreas Rumpf
    git hash: 0565a70eab02122ce278b98181c7d1170870865c
    active boot switches: -d:release

Now head over to https://nim-lang.org/learn.html to learn this awesome ❤️ language!

Versions used: nim 1.6.6 , os CentOS 7.6.1810
This is Day 19 of #100DaysToOffload.