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