Introduction / Why This Is Needed
Nim is a statically typed compiled language that combines Python's expressiveness with C's performance. Installing Nim on Debian opens up opportunities for developing system software, embedded applications, games, and high-load servers. After completing this guide, you will have a fully configured environment for compiling and running Nim code.
Requirements / Preparation
Before you begin, ensure that:
- You have a 64-bit Debian 11 (Bullseye) or newer system.
- You have access to an account with
sudoprivileges to install system packages. - The terminal is connected to the internet for downloading files.
Mandatory System Packages
Open a terminal and install the build tools:
sudo apt update
sudo apt install -y build-essential curl git
build-essential— providesgcc,make, and other basic compilation utilities.curl— for downloading the installation script.git— recommended for working with dependencies via Nimble.
Step-by-Step Guide
Step 1: Installing choosenim
The official and recommended way to install Nim is through the version manager choosenim. It automatically downloads and manages multiple versions of the compiler.
Run in the terminal:
curl https://nim-lang.org/choosenim/init.sh -sSf | sh
The script will ask if you want to add Nim to your PATH. Answer y (yes).
Step 2: Configuring the PATH Environment Variable
After installation, choosenim adds the path to the binaries in the ~/.profile file. To apply the changes in the current terminal session, run:
source ~/.profile
Or simply close and reopen the terminal.
Step 3: Installing the Selected Nim Version
Now that choosenim is installed, use it to install the latest stable version of Nim:
choosenim stable
The process will take several minutes as the compiler sources are downloaded and compiled. At the end, you will see a success message.
Step 4: Verifying the Installation
Ensure the compiler is available and working:
nim --version
The output should look something like:
Nim Compiler Version 2.0.0 [Linux: amd64]
Compiled at 2026-02-10
...
Also check that the Nimble package manager is working:
nimble --version
Step 5: Creating and Running a Test Project
Let's create a simple project to ensure everything works end-to-end.
- Create a new directory and navigate to it:
mkdir ~/nim_test && cd ~/nim_test - Create a file
hello.nimwith the content:echo("Привет, мир Nim на Debian!") - Compile and run it with a single command:
You should see the output:nim r hello.nimПривет, мир Nim на Debian!
Verifying the Result
A successful installation is confirmed by meeting the following conditions:
- The
nim --versioncommand does not return a "command not found" error. - The compiler version matches the latest stable (e.g., 2.0.x).
- The newly created test script successfully compiled and executed.
Potential Issues
Error: nim: command not found
Cause: The path to Nim's executables is not added to the PATH variable.
Solution: Ensure you ran source ~/.profile or added export PATH="$HOME/.nimble/bin:$PATH" to the end of ~/.bashrc (or ~/.zshrc for Zsh) and restarted the terminal.
Compilation Error: cc: command not found or make: not found
Cause: The build-essential packages are not installed.
Solution: Install them as shown in the Requirements section: sudo apt install build-essential.
choosenim Cannot Download Files (Timeout/SSL Error)
Cause: Issues with network connection or outdated root certificates.
Solution: Ensure the system has internet access. Try updating ca-certificates: sudo apt install ca-certificates. If the problem persists, you can manually download the archive from the official website and unpack it into ~/.nimble.
Installing Nim via apt (Not Recommended)
Although the Debian repositories contain a nim package (sudo apt install nim), it almost always contains a heavily outdated version. Use this method only if you critically need the repository version for compatibility, and be prepared for manual updates. For development, always choose choosenim.