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