nix-env
Install, upgrade, and remove Nix packages
TLDR
List all installed packages
Query installed packages
Query available packages
Install package
Install a package from a URL
Uninstall package
Upgrade one package
Upgrade all packages
SYNOPSIS
nix-env [OPTIONS] { -i | -u | -e | -q | -S | --compare-generations | --rollback | --switch-generation | --delete-generations | --list-generations } [ARGUMENTS]
PARAMETERS
-i, --install
Installs packages into the user's profile.
-u, --upgrade
Upgrades packages in the user's profile to their latest versions.
-e, --erase
Erases (uninstalls) packages from the user's profile.
-q, --query
Queries packages. Can list installed, available, or selected packages.
-S, --search
Searches for packages available in the Nix channels.
-f
Specifies a Nix expression file to evaluate for packages.
-A
Selects packages by attribute path (e.g., 'nixpkgs.hello').
-I
Adds a path to the Nix expression search path.
--dry-run
Shows what would be done without actually performing the action.
--xml
Outputs information in XML format.
--json
Outputs information in JSON format.
--list-generations
Lists all existing generations of the current user profile.
--rollback
Rolls back the current user profile to the previous generation.
--switch-generation
Switches the current profile to a specific generation number.
DESCRIPTION
The nix-env command is a fundamental tool within the Nix ecosystem for managing per-user software environments, often referred to as 'profiles'. It allows users to imperatively install, upgrade, or remove packages from the Nix store without affecting other users or system-wide installations.
Unlike traditional package managers, nix-env operates transactionally. Each change to a user's profile creates a new 'generation', enabling instant rollbacks to previous states if an update or installation goes wrong. This command sources packages from Nix channels, which are typically synchronized with a set of Nix expressions defining available software. While powerful for individual users, its imperative nature has led to the development of more declarative alternatives like the nix profile subcommand from the unified nix CLI, particularly for system-wide package management in NixOS.
CAVEATS
While powerful for individual package management, nix-env is generally not recommended for declarative system-wide package management in NixOS; that role belongs to nixos-rebuild. Its imperative nature can sometimes lead to an environment that's harder to reproduce precisely compared to fully declarative Nix configurations. For modern Nix usage, the nix profile subcommand (part of the unified nix CLI) is often preferred as a more structured and extensible replacement for user environment management.
GENERATIONS
Every successful operation with nix-env (install, upgrade, erase) creates a new 'generation' of the user's profile. This allows for atomic updates and instant rollbacks to any previous state, providing a robust mechanism for recovering from broken configurations without complex manual intervention. Generations are managed symphonically with the Nix store.
PROFILES
nix-env manages 'user profiles', which are essentially symlink trees in ~/.nix-profile (or similar paths) pointing to specific package sets in the Nix store. Each user can have their own isolated profile, allowing different users on the same system to have distinct sets of software installed without conflicts.
HISTORY
nix-env is one of the original and foundational user-facing commands in the Nix package manager. It predates the introduction of the unified nix command (often referred to as 'nix-cli' or 'new-cli'). Its design focused on providing robust, transactional per-user package management, a concept central to Nix's atomic upgrades and rollbacks. Over time, while still widely used and available for compatibility, much of its functionality has been superseded by the nix profile subcommand in the newer nix CLI, which offers a more consistent interface with other Nix commands like nix run and nix shell.
SEE ALSO
nix(1), nix-store(1), nix-build(1), nix-shell(1), nixos-rebuild(8)