The modern Nix commands (nix search, nix shell, nix run, nix build,
nix profile) replace the old tools (nix-env, nix-build, nix-shell) with
a unified interface and more readable outputs. This guide covers the daily
workflow: search for a package, try it without installing it, add
it to the profile, build it locally, and inspect its metadata. Every
command was replayed on Nix 2.35.2, in the official nixos/nix image, with
the nixpkgs-unstable of 29 September 2026.
What you will learn
- Search for a package in nixpkgs with
nix search - Run a temporary binary with
nix shellandnix run - Manage installed packages with
nix profile(add, remove, upgrade) - Build a package locally with
nix build - Inspect the metadata and dependencies of a package
- Know the utility commands (
nix eval,nix path-info,nix why-depends)
In what context?
The modern commands are enabled by the
experimental-features = nix-command flakes option in /etc/nix/nix.conf.
They cover most of the daily needs of an administrator who wants to keep
the system clean:
- try a tool quickly without polluting the system (demo, debugging, version comparison),
- install user tools without root rights and without dependency conflicts,
- build a project reproducibly before deploying it,
- inspect the dependencies of a package before shipping it in a container or a VM.
Search for a package: nix search
nix search queries a flake whose name you must give as the first
argument, here nixpkgs. This is what sets it apart from apt search: the
command does not search "the available packages" in general, but the
collection you designate. The exact name returned, for example
legacyPackages.x86_64-linux.htop, is the one the other Nix commands will
expect afterwards.
Keyword search
The term is searched in the attribute path, the name and the
description of the packages, which explains the number of results for a
common word: abtop shows up here because its description mentions htop.
nix search nixpkgs htop* legacyPackages.x86_64-linux.abtop (0.5.5)* legacyPackages.x86_64-linux.htop (3.5.3)* legacyPackages.x86_64-linux.htop-vim (3.5.3)* legacyPackages.x86_64-linux.neohtop (1.2.0)The first evaluation of nixpkgs takes 30 to 60 seconds (evaluation of the full tree). The following searches use a local cache and are almost instant.
Search with a regular expression
nix search accepts regular expressions to narrow things down. Beware: the
expression is tested separately against the attribute path, the package
name and its description, and a single match is enough.
nix search nixpkgs "^python3$"* legacyPackages.x86_64-linux.buildbotPackages.python (3.14.7)* legacyPackages.x86_64-linux.jupyter (3.14.7-env)* legacyPackages.x86_64-linux.llm (3.14.7-llm-0.31.1)* legacyPackages.x86_64-linux.python3 (3.14.7)* legacyPackages.x86_64-linux.python311 (3.11.16)On this nixpkgs, the command returns 17 results, not just python3:
jupyter or llm are Python environments whose package name is exactly
python3. The ^...$ anchor does rule out variants such as
python3Packages.*, but not these namesakes; to check a precise attribute,
nix eval is more direct.
Display the metadata
To get the description of a package:
nix eval nixpkgs#hello.meta.description"Program that produces a familiar, friendly greeting"Try without installing: nix shell and nix run
These two commands download the package into the store and make it executable immediately, without ever touching the profile or the system. This is the usage that replaces the classic "I install it to try, I will uninstall it afterwards": there is nothing to uninstall since nothing was installed. The package still takes up disk space until the next garbage collection.
nix shell, a temporary shell with packages
nix shell opens a new shell with the requested packages in the
$PATH. Nothing is installed in the profile:
nix shell nixpkgs#cowsay -c cowsay "Temporary Nix shell" _____________________< Temporary Nix shell > --------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||After it runs, cowsay is no longer available:
which cowsay# cowsay not foundThe -c option runs a single command and exits. Without -c, an
interactive shell opens with the packages in the $PATH, until you type
exit.
Combine several packages
Each extra package is added as a separate argument, prefixed with its flake: there is no separator and no list to quote.
nix shell nixpkgs#jq nixpkgs#curl -c sh -c 'curl -s https://api.github.com/repos/NixOS/nix | jq .stargazers_count'Both packages are available in the same temporary shell: jq 1.8.2 and
curl 8.22.0 on the nixpkgs of the day. The sh -c is needed because the
pipe has to be interpreted by a shell.
nix run, run a binary directly
nix run downloads the package and runs its main binary without opening a
shell:
nix run nixpkgs#bat -- --versionbat 0.26.1The -- separates the arguments of nix run from those passed to the
binary: without it, --version would be read by nix itself and would
print the Nix version.
Difference between nix shell and nix run
The four forms below differ on two points: whether a shell is opened, and
whether several packages are reachable. Remember that nix run only
launches the main binary declared by the package, which excludes the
additional tools it installs alongside; in that case, use nix shell.
| Command | Behaviour | Use case |
|---|---|---|
nix shell nixpkgs#tool | Opens a shell with tool in the $PATH | Explore, run several commands |
nix shell nixpkgs#tool -c cmd | Runs cmd in a temporary shell | Script, pipeline |
nix run nixpkgs#tool | Runs the main binary directly | Quick test, one-shot |
nix run nixpkgs#tool -- args | Runs with arguments | Check a version, start a server |
Manage installed packages: nix profile
The profile is the set of packages made permanently available to your
account, without root rights and without conflict with those of the
distribution. Every operation creates a numbered generation in it, which
makes installation and removal reversible. The subcommands follow the same
logic as any package manager: add, list, remove, upgrade.
Add a package
No sudo is needed: the package is added to the profile of the current
user, not to the system.
nix profile add nixpkgs#fdfd is now permanently available in your $PATH:
fd --versionfd 10.5.0List installed packages
For each entry, the output gives the requested source (flake:nixpkgs),
the nixpkgs locked revision at the time it was added, and the store
path, the only way to know the version actually installed, since the package
name does not contain it.
nix profile listName: fdFlake attribute: legacyPackages.x86_64-linux.fdOriginal flake URL: flake:nixpkgsLocked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3DStore paths: /nix/store/4xblm8snjdb609iygrqyrx9l07mqfp2c-fd-10.5.0
Name: jqFlake attribute: legacyPackages.x86_64-linux.jqOriginal flake URL: flake:nixpkgsLocked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3DStore paths: /nix/store/gpc36qrvyhyqb6axmj1c0ivx74ni7d8d-jq-1.8.2-man /nix/store/m3y7hqmy20nd1ps6qy8410a326255bf0-jq-1.8.2-bin
Name: ripgrepFlake attribute: legacyPackages.x86_64-linux.ripgrepOriginal flake URL: flake:nixpkgsLocked flake URL: https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=sha256-k8Fu4c9Z%2B4Nh7mUr0cfw%2B%2BITQiyEhlWxoJBOkI3tOcQ%3DStore paths: /nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0Remove a package
Removal is done by package name, not by the full flake reference used at installation.
nix profile remove fdremoving 'flake:nixpkgs#legacyPackages.x86_64-linux.fd'removed 1 packages, kept 2 packagesThe fd binary disappears from the $PATH immediately. The package stays in
the store until garbage collection.
Upgrade packages
To upgrade a specific package, designate it by its name:
nix profile upgrade ripgrepTo upgrade all the packages of the profile, use --all:
nix profile upgrade --allupgrading 'legacyPackages.x86_64-linux.jq' from flake 'https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=...' to 'https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1082290.b6c8664de9b6/nixexprs.tar.zst?narHash=...'The old form nix profile upgrade '.*', still quoted by many tutorials, no
longer works: Nix 2.35.2 answers
warning: Package name '.*' does not match any packages in the profile. and
upgrades nothing.
History and rollback
Every operation on the profile creates a generation. Look at the history and go back if needed:
nix profile historynix profile rollback # back to the previous generationnix profile rollback --to 2 # switch to a specific generationBuild locally: nix build
nix build produces a package in the store without adding it to the profile,
so without making it available in the $PATH. In practice the build is often
instant: Nix first checks whether the result already exists in the public
binary cache and then simply downloads it. A local compilation only
happens if no prebuilt version matches exactly.
Build and inspect the result
nix build builds (or downloads from the cache) a package and creates a
result symbolic link in the current directory:
nix build nixpkgs#hellols -la resultresult -> /nix/store/5z2yp3ysx8476c8g5w25b0smlgkjvaq3-hello-2.12.3./result/bin/helloHello, world!The result link acts as a GC root: as long as it exists, the package
will not be deleted by the garbage collector.
Build without a symbolic link
Without a result link, there is no GC root any more: the built package
becomes eligible for deletion at the next garbage collection.
nix build nixpkgs#hello --no-linkThe package is built in the store but no result link is created. Useful
to prefill the cache without cluttering the current directory.
Inspect packages: utility commands
These three commands answer the questions that come up before shipping a package in a container image or a VM: how much does it weigh once its dependencies are counted, why does it pull in a given library, and how is it built. None of them modifies the profile or the system.
nix path-info, path and size in the store
With no option, the command only prints the path; you need -s for the
own size, -S for the closure and -h for readable units.
nix path-info nixpkgs#ripgrep/nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0With the sizes (own and closure):
nix path-info -sSh nixpkgs#ripgrep/nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0 6.7 MiB 55.7 MiBThe first column of figures is the own size of the package, the second its closure size (all dependencies included).
nix why-depends, trace a dependency
To understand why a package depends on another, give both to
nix why-depends. The target must designate a single store path: since
pcre2 produces several outputs (out, bin, man…), you have to name
the one you are looking for, here .out.
nix why-depends nixpkgs#ripgrep nixpkgs#pcre2.out/nix/store/vli6118fdbngwy46j1w741ansmrzfszr-ripgrep-15.2.0└───/nix/store/7v8b5idfzwfl06hx6n0cvd5ikd5p0sbg-pcre2-10.48Without .out, Nix 2.35.2 refuses with
error: argument 'flake:nixpkgs#pcre2' should evaluate to one store path.
nix derivation show, build recipe
The output is a large JSON document, hence the head -c 400 of the example;
the 2>&1 redirection also captures the evaluation messages printed on the
error output.
nix derivation show nixpkgs#hello 2>&1 | head -c 400{"derivations":{"cnraiw0hbdl6jzdhbkn8dah2hqj7xgij-hello-2.12.3.drv":{"args":["-e","/nix/store/l622p70vy8k5sh7y5wizi5f2mic6ynpg-source-stdenv.sh","/nix/store/shkw4qm9qcw5sc5n1k5jznc83ny02r39-default-builder.sh"],"builder":"/nix/store/10dxp0qxqxxsyiljrh2kp0xqhz6arhcx-bash-5.3p15/bin/bash","env":{"out":"/nix/store/5z2yp3ysx8476c8g5w25b0smlgkjvaq3-hello-2.12.3"},A derivation is the complete recipe to build a package: sources, dependencies, builder, environment variables. It is the fundamental element that guarantees reproducibility.
Summary of the commands
The right-hand column is the most useful day to day: it separates the commands
that leave the system unchanged from those that create a new profile
generation. The former have no consequence and can be tried freely; the
latter are undone with nix profile rollback.
| Command | Usage | Modifies the profile? |
|---|---|---|
nix search nixpkgs <term> | Search for a package | No |
nix shell nixpkgs#pkg | Temporary shell with the package | No |
nix run nixpkgs#pkg | Run the main binary | No |
nix build nixpkgs#pkg | Build and create ./result | No |
nix profile add nixpkgs#pkg | Install into the profile | Yes |
nix profile remove pkg | Uninstall from the profile | Yes |
nix profile upgrade pkg (or --all) | Upgrade | Yes |
nix profile list | List installed packages | No |
nix profile history | History of generations | No |
nix profile rollback | Back to the previous generation | Yes |
nix eval nixpkgs#pkg.attr | Evaluate an expression | No |
nix path-info nixpkgs#pkg | Path and size in the store | No |
nix why-depends A B | Trace a dependency | No |
nix derivation show nixpkgs#pkg | Show the recipe (.drv) | No |
Key points
nix searchexplores the 100,000+ packages of nixpkgs, the first evaluation is slow, the following ones are instant.nix shellandnix runlet you try a tool without installing it, ideal for debugging or comparing versions.nix profilemanages permanently installed packages with a full history and an atomic rollback;nix profile upgrade --allupgrades everything.nix buildbuilds a package and creates aresultlink, useful to inspect or deploy the result.- The utility commands (
eval,path-info,why-depends,derivation show) help understand how a package is made up. - All these commands use the
nixpkgs#packagesyntax to designate a package, a flake reference, detailed in the Flakes guide.
Knowledge check
Check that the essentials of this guide are acquired. The questions only cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Classic Nix commands: nix-env, nix-build, nix-shell, nix-channel
A new full quiz with random questions
Work again only on the questions you missed