Installation, Tooling and First Program

2.1 Installing Nim

choosenim (toolchain manager, like rustup):

Windows: the official zip/installer from nim-lang.org (bundles MinGW), scoop install nim, or choosenim.

Linux/macOS: package managers (brew install nim, apt install nim), but they may lag behind.

Verify: nim -v, nimble -v.

curl https://nim-lang.org/choosenim/init.sh -sSf | sh
choosenim stable          # install / switch to latest stable
choosenim devel           # nightly
choosenim 2.0.8           # specific version

2.2 The Toolchain

Compiler (nim c, nim cpp, nim js, nim doc, nim check, nim e) Package manager and build tool

IDE support (autocomplete, go-to-definition) Test runner used by the compiler itself

Workspace/dependency cloner (alternative to Nimble)

2.3 Editor Setup

VS Code: the "Nim" extension (by nim-lang), using nimlangserver.

Neovim/Vim (nimlsp/nimlangserver via LSP), Emacs (nim-mode), JetBrains (Nim plugin), Sublime.

2.4 Hello, World

Build artifacts go to ~/.cache/nim/ (the nimcache). Use --outdir:bin and -o:name.

# hello.nim
echo "Hello, World!"
nim c -r hello.nim          # compile + run (C backend)
nim c -d:release hello.nim  # optimized build
nim r hello.nim             # shortcut for compile and run (binary cached)
nim js -r hello.nim         # JavaScript backend (needs node)

2.5 Reading Input

import std/strutils
stdout.write "What's your name? "
let name = readLine(stdin)
let age = parseInt(readLine(stdin))
echo "Hello, ", name, "! Next year you'll be ", age + 1

2.6 Compilation Pipeline

.nim source → Nim compiler (parse → semantic check → transform → codegen) → C/C++/JS source → C compiler → native binary