1<section xmlns="http://docbook.org/ns/docbook"
2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xmlns:xi="http://www.w3.org/2001/XInclude"
4 version="5.0"
5 xml:id="sec-ad-hoc-packages">
6 <title>Ad-Hoc Package Management</title>
7
8 <para>
9 With the command <command>nix-env</command>, you can install and uninstall
10 packages from the command line. For instance, to install Mozilla Thunderbird:
11<screen>
12$ nix-env -iA nixos.thunderbird</screen>
13 If you invoke this as root, the package is installed in the Nix profile
14 <filename>/nix/var/nix/profiles/default</filename> and visible to all users
15 of the system; otherwise, the package ends up in
16 <filename>/nix/var/nix/profiles/per-user/<replaceable>username</replaceable>/profile</filename>
17 and is not visible to other users. The <option>-A</option> flag specifies the
18 package by its attribute name; without it, the package is installed by
19 matching against its package name (e.g. <literal>thunderbird</literal>). The
20 latter is slower because it requires matching against all available Nix
21 packages, and is ambiguous if there are multiple matching packages.
22 </para>
23
24 <para>
25 Packages come from the NixOS channel. You typically upgrade a package by
26 updating to the latest version of the NixOS channel:
27<screen>
28$ nix-channel --update nixos
29</screen>
30 and then running <literal>nix-env -i</literal> again. Other packages in the
31 profile are <emphasis>not</emphasis> affected; this is the crucial difference
32 with the declarative style of package management, where running
33 <command>nixos-rebuild switch</command> causes all packages to be updated to
34 their current versions in the NixOS channel. You can however upgrade all
35 packages for which there is a newer version by doing:
36<screen>
37$ nix-env -u '*'
38</screen>
39 </para>
40
41 <para>
42 A package can be uninstalled using the <option>-e</option> flag:
43<screen>
44$ nix-env -e thunderbird
45</screen>
46 </para>
47
48 <para>
49 Finally, you can roll back an undesirable <command>nix-env</command> action:
50<screen>
51$ nix-env --rollback
52</screen>
53 </para>
54
55 <para>
56 <command>nix-env</command> has many more flags. For details, see the
57 <citerefentry>
58 <refentrytitle>nix-env</refentrytitle>
59 <manvolnum>1</manvolnum></citerefentry> manpage or the Nix manual.
60 </para>
61</section>