I use Windows (company-supplied) for work, MacBook Pro (given by a friend) for everyday use, and Manjaro Linux (given by a senior company) for experimentation, all of which are package managers. I'm using nix. (However, Windows uses Nix in Ubuntu on WSL2)
The reason why I use Nix instead of using apt or homebrew quietly is
I'm happy about that.
I want Nix to become more popular, so I'll show you how to install the Nix package manager and how to use basic commands.
Linux
$ sh <(curl -L https://nixos.org/nix/install)
One caveat is that you can't run it with a fish shell.
macOS
$ sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
In ~ / .bashrc
to set the necessary environment variables to use nix on both Linux and Mac
if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then
. $HOME/.nix-profile/etc/profile.d/nix.sh;
fi
Let's add.
First, you need to subscribe to a Unix package channel to use it.
Use the nix-channel
command to manipulate channels.
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
nix-channel --update
is like sudo apt update
.
The main command for package management is nix-env
.
You can use nix-env
to install, upgrade, remove, search for packages, and more.
You can browse all installable packages with nix-env -qa
.
The same is true for nix-env --query --available
.
$ nix-env -qa
aterm-2.2
bash-3.0
binutils-2.15
bison-1.875d
blackdown-1.4.2
bzip2-1.0.2
...
You can search for a specific package by putting the name of the package after -qa
.
$ nix-env -qa firefox
firefox-68.11.0esr
firefox-78.1.0esr
firefox-79.0
You can also use regular expressions to search.
$ nix-env -qa 'firefox-.*'
You can install the package with nix-env -i
or nix-env --install
.
By the way, you don't need sudo
. Installed packages are installed by the user, not the system. There is (probably) no impact on the entire system.
$ nix-env -i subversion
You can check all installed packages with nix-env -q
.
$ nix-env -q
nix-2.3.7
subversion-1.12.2
You can update your environment with nix-env -u
or nix-env --upgrade
.
When upgrading only a specific package,
$ nix-env -u subversion
When upgrading all installed packages,
$ nix-env -u
You can uninstall the package with nix-env -e
or nix-env --erase
.
nix-env -e subversion
uninstalling 'subversion-1.12.2'
rollback
Nix creates a generation for your environment each time you add or remove a package. And you can roll back to those generations at any time.
For example, it is useful when you have installed a package and had a bug and want to revert to a working installation.
Check generations nix-env --list-generations
$ nix-env --list-generations
1 2020-08-03 23:36:12
2 2020-08-06 19:15:43
3 2020-08-06 19:55:13
4 2020-08-09 18:33:59
5 2020-08-09 18:34:46 (current)
(current)
is the current environment.
Use nix-env --rollback
to return to the previous environment.
$ nix-env --rollback
switching from generation 5 to 4
$ nix-env --list-generations
1 2020-08-03 23:36:12
2 2020-08-06 19:15:43
3 2020-08-06 19:55:13
4 2020-08-09 18:33:59 (current)
5 2020-08-09 18:34:46
To move to a specific generation, use nix-env --switch-generation
.
$ nix-env --switch-generation 2
switching from generation 4 to 2
Recommended Posts