Nix Package Manger Basics


search available packages nix --extra-experimental-features "nix-command flakes" search nixpkgs firefox nix-env -qaP

Install new package nix-env -iA nixpkgs.gimp

delete package nix-env -e gimp

list installed packages nix-env -q


list generations nix-env --list-generations

switch generations nix-env --switch-generation 50

delete generation nix-env --delete-generations old

delete specific generations nix-env --delete-generations 10 11 14

delete generation older than specific number of days nix-env --delete-generations 14d

Garbage Collection (cleanup)

After removing appropriate old generations you can run the garbage collector as follows: nix-store --gc

If you are feeling uncertain, you can also first view what files would be deleted:

nix-store --gc --print-dead

Likewise, the option --print-live will show the paths that won’t be deleted.

There is also a convenient little utility nix-collect-garbage, which when invoked with the -d (--delete-old) switch deletes all old generations of all profiles in /nix/var/nix/profiles. So

 nix-collect-garbage -d

is a quick and easy way to clean up your system.