Installation Guide

Learn how to install Nix package manager on a non-NixOS machine

guide

Installing the Nix package manager on a non‑NixOS machine is a straightforward process that opens up a powerful, reproducible package ecosystem. Below is a step‑by‑step guide that covers prerequisites, installation, verification, basic usage, and advanced configuration options, all written in a technical yet approachable style.

Prerequisites

  • 64‑bit Linux (kernel 4.15+) or macOS (10.15+)
  • At least 1 GB of free disk space for the Nix store
  • On macOS, install Xcode command line tools (xcode-select --install) and ensure libiconv and libffi are available (e.g., via Homebrew).
  • On Linux, install build essentials (gcc, make, libc6-dev) if you plan to compile packages.

Step 1 – Run the Installer
sh <(curl -L https://nixos.org/nix/install)
The script auto‑detects your OS, downloads the correct binary, and creates the Nix store under /nix/store on both Linux and macOS. It also writes a user‑specific configuration file at ~/.config/nix/nix.conf and updates your shell profile (~/.bashrc, ~/.zshrc, etc.) to add /nix/var/nix/profiles/default/bin to your PATH.

Step 2 – Verify the Installation
nix-env --version
nix-env -qaP hello
The first command shows the Nix version; the second lists available packages, confirming that the store is reachable.

Step 3 – Install a Package
nix-env -iA nixpkgs.hello
nix-env manages user‑specific packages. For system‑wide packages, use a dedicated profile:
nix-env --profile /nix/var/nix/profiles/system -iA nixpkgs.hello
Alternatively, create a configuration.nix and run nix-env --switch-profile.

Step 4 – Configure Nix
Edit ~/.config/nix/nix.conf to enable features and set defaults. Common entries:

experimental-features = nix-command flakes
trusted-users = root @users
sandbox = true
  • experimental-features unlocks the new nix command syntax and flakes support.
  • trusted-users allows non‑root users to perform privileged operations.
  • sandbox enforces isolation during builds.

For automated maintenance, enable the garbage‑collector daemon and set retention policies:

gc-keep-older-than = 7d

Step 5 – Explore Flakes
Create a flake.nix in any project directory:

{
  description = "Example flake";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = { self, nixpkgs }: {
    devShell.x86_64-linux = nixpkgs.mkShell {
      buildInputs = [ nixpkgs.hello ];
    };
  };
}

Run nix develop . to spawn a development shell with the specified dependencies. Use nix flake show to inspect outputs and nix flake update to refresh inputs.

Step 6 – Advanced System Configuration
Even on non‑NixOS systems, you can use nix-env for package installation and nix-shell for isolated environments. For declarative system configuration, create a configuration.nix and apply it with nixos-rebuild switch (available on NixOS) or use nix-env --switch-profile on other systems.

Summary

  1. Run the installer script.
  2. Add Nix to your PATH.
  3. Verify with nix-env.
  4. Install packages with nix-env -iA.
  5. Configure via ~/.config/nix/nix.conf.
  6. Embrace flakes for reproducible development environments.

With these steps, you’ll have a fully functional Nix installation on any modern Linux or macOS machine, ready to manage packages, build reproducible environments, and experiment with the powerful flakes system.