GrabNim is a simple tool to install and switch between different versions of the Nim compiler.
This project started as a script I wrote out of frustration with choosenim.
Features:
Comparison with choosenim:
Basic Usage:
grabnim # Install latest stable Nim
grabnim fetch # Show available versions for your OS
grabnim 2.2.4 # Install specific version
grabnim compile devel # Install from source
grabnim list # Show installed versions
Installation:
wget https://codeberg.org/janAkali/grabnim/raw/branch/master/misc/install.sh
sh install.sh
Or download from releases and setup PATH env.
Project Page: https://codeberg.org/janakali/grabnim
GrabNim makes it easy to test your code against different Nim versions. Give it a try and let me know what you think!
compile.nim module is heavily-based on nimenv.
I only had to rewire types and some git procs to grabnim internals.
Awesome work!
I was working on something similar myself, but you beat me to it :)
Demo:
If you're using grabnim on Windows - there's a new flag to automatically setup your PATH env:
grabnim setup
It'll confirm if .nimble and grabnim/current directories are already in PATH and ask you for confirmation before adding them.
Great Projrct!
I have tried it and it's much better than choosenim.
but one more suggestion from nodejs https://nodejs.org/en/download/current
# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# in lieu of restarting the shell
\. "$HOME/.nvm/nvm.sh"
# Download and install Node.js:
nvm install 24
# Verify the Node.js version:
node -v # Should print "v24.4.0".
nvm current # Should print "v24.4.0".
# Verify npm version:
npm -v # Should print "11.4.2".
maybe we can do this?
# Download and install nvm (Nim Version Manager):
curl -o- https://codeberg.org/janAkali/grabnim/raw/branch/master/misc/install.sh | bash
# Download and install Nim:
nvm 2.2.4
# Verify theNim version:
nim -v # Should print "v2.2.4".
# Verify nimble version:
nimble -v
Fixes:
Features:
Demo "From Zero to Compiling" (recorded in Wine):
I just tried grabnim out and it's pretty good! I am having problems trying to run it in a Github Action however. I'm getting:
Failed to get content from 'https://api.github.com/repos/nim-lang/nightlies/releases/tags/latest-version-2-2'. Error:403 rate limit exceeded
This occurs on macos-runners because there still doesn't appear to be an arm64 binary in the release :/ . Grabnim tries to look up the latest latest-2-2 but fails with the 403 rate limit.
Grabnim tries to look up the latest latest-2-2 but fails with the 403 rate limit.
Yeah, this is a known problem. Github API allows only 60 requests per hour per IP for unauthenticated users. So if you're using some shared connection, or in this case - Github Runner, it's too easy to exhaust these limits.
I've updated GrabNim to use GitHub's Personal Access Token for API calls (can be set in GRABNIM_GITHUB_TOKEN env variable). And here's a new section in the README with instructions on how to generate and use this token - https://codeberg.org/janAkali/grabnim#fixing-github-api-403-errors-rate-limits-access-denied
Awesome thanks!
Do you know why installing a release version fails? Say 2.2.4 on macos arm64. I did a quick check but only found the github logic. How are official releases found?
GrabNim scrapes release urls <https://codeberg.org/janAkali/grabnim/src/commit/5474b2da124dc460127f1e02fc392eebfea98cb4/grabnim.nim#L88-L102> from "https://nim-lang.org/install.html" webpage. Then it parses the platform from archive names and compares it to host OS:
# utils/osextra
proc getCompatibleNimOrgOS(): OStype =
case hostOS
of "windows":
case hostCPU
of "amd64": Windows_x64
of "i386": Windows_x32
else: Unknown
of "linux", "macosx", "netbsd", "freebsd", "openbsd":
case hostCPU
of "amd64": Unix_x64
of "i386": Unix_x32
else: Unknown
else: Unknown
Grabnim fails to find 2.2.4 ARM64 release, because nim-lang.org website only has releases for x86(x32) and x64 CPU architecture. But Nightlies do have an arm64 build, so we use it as a fallback for the default "install latest" command.
You made me aware of grabnim in my thread. Thank you! So far I quite like it and think it's better than choosenim which, granted is a low barrier.
Thanks again!
New `disable` command
Use disable command to temporarily turn off grabnim's current link. Useful when you need to use a different Nim installation:
grabnim off # deletes grabnim link
nim --version # use system-installed nim compiler
grabnim 2.2.4 # switch to grabnim-installed compiler
Smarter `update` command
The update command now checks if an update is needed before updating. This should prevent unnecessary downloads when you already have the latest version.
Local compiler builds
You can now add your own Nim compiler builds. Just place them in Grabnim directory with name starting with local-. Grabnim will detect any directory that starts with local- and contains a bin/nim executable.
Example:
mv /path/to/custom/nim ~/.local/share/grabnim/local-mybuild # move
ln -s /path/to/custom/nim ~/.local/share/grabnim/local-mybuild # or create link
grabnim list # local builds appear in 'list' output
grabnim local-mybuild # switching is supported
grabnim delete local-mybuild # delete command is supported
Get it from releases: https://codeberg.org/janAkali/grabnim/releases