I have an installation of nix on a Linux system, and I have added the channel nixpkgs-unstable. I can now install packages such as gcc:

% nix-env --install gcc
installing 'gcc-7.4.0'
created 78 symlinks in user environment

If I look into a directory such as ~/.nix-defexpr/channels/nixpkgs/pkgs/development/compilers/gcc/, I will discover that there is a variety of versions, all complete with default.nix.

  • How can I discover these hidden package versions with ghc-env --query, or some other friendly tool?

  • Suppose I wish to install gcc version 8 to my user environment, how should I go about it? Can I obtain several versions of gcc at once?

I have been browsing the voluminous documentation of Nix, but everywhere they say something along the lines of "with Nix, you can install any number of versions at once and they will never conflict" and at the same time "you are supposed to only install one version at a time, that is hardcoded in your channel of choice". What sense does it make?

2 Answers 2


You can see all past versions of a package and how to install them from here https://lazamar.co.uk/nix-versions

Nix only keeps the latest version of a package in a derivation. If multiple major versions are popular (like python2 and python3) the latest version of each will be listed.

Unfortunately nix does not have a native way to search all versions of a package that were available in the past in previous derivations.

I wrote the tool linked to address exactly this problem.


I'd suggest to use attribute paths, e.g. nix-env -iA nixpkgs.gcc8 in your case where "nixpkgs" is because you named your channel that way (NixOS users will typically use "nixos" name). The attribute paths are unambigous, contrary to normal names.

How to discover these? One way is e.g. adding -P to nix-env -qa queries. I usually use tab-completion in nix repl or browse the all-packages.nix file :-) (unless I know or attempt to guess the attrpath)

Side notes:

  • If you tried to have multiple versions in a single profile at once (e.g. by nix-env), you would normally get conflicts when creating the profile's symlink tree unless you set priorities.
  • Inside a single channel version (i.e. nixpkgs commit), we try to keep the number of versions and configurations of each package at minimum, usually just one. That's motivated by saving resources (to build and distribute the binaries) and better quality/maintenance.
  • Thank you. Unfortunately, -P still does not list multiple versions of the same package. (Perhaps it should?) Can you please elaborate how to use nix repl for this? Also, how can I set these priorities? For instance, I installed gcc8 and now gcc symlinks to this. Do I have to create links, such as gcc-7.4.0, gcc-8.3.0 and so on, by hand? Jul 9, 2019 at 21:41
  • Also, this method will not work with, for instance, ghc, because there I have several versions of .nix files rather than directories, each with a default.nix. I cannot select any of them with nix-env. Jul 10, 2019 at 3:25
  • nix-env -qaP | grep 'gcc[0-9]\>' shows five different versions for me. It's true not everything is showed by nix-env, with haskellPackages being a notable example - but note that isn't due to directory structure but explicit dontRecurseIntoAttrs request in the sources. Jul 10, 2019 at 20:43
  • You are right. I must have done something wrong the last time I was checking. Jul 10, 2019 at 22:19
  • @IgnatInsarov I think you use overlays for that, no manual symlinking
    – madhukar93
    Mar 23, 2020 at 5:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .