Use the Nix package manager on any Linux OS
NixOS is a declarative Linux operating system. Users create their operating system from the ground up with a configuration file and the use of an excellent package manager. But did you know it is possible to use the Nix package manager on any Linux operating system? Here’s how to get it working on your Linux PC.
How do you install the Nix package manager on Linux?
The Nix package manager (that comes with NixOS) can be installed on any Linux operating system. However, you’ll need a terminal window to install it on your Linux OS. So, how do you open up a terminal window? Press Ctrl + Alt + T on the keyboard. Or, search for “Terminal” in the app menu.
Once the terminal window is open and ready to use, you can install the Nix package manager using the curl command. Don’t have the Curl app installed on your Linux PC? Install it with the commands below.
Ubuntu
sudo apt install curl
Debian
sudo apt-get install curl
Arch Linux
sudo pacman -S curl
Fedora
sudo dnf install curl
OpenSUSE
sudo zypper install curl
The Nix package manager is installed via a script, and there are two ways to install it. Multi-user and Single-user. You’ll want to run the –no-daemon command version to install it on your system as a single user.
sh <(curl -L https://nixos.org/nix/install) --no-daemon
Once you’ve executed the command above, the script will ask you for your password (to use sudo). Using the keyboard, enter the password associated with your user account.
Alternatively, if there is more than one user on your computer, you will need to run the –daemon command. Every user can constantly interact with the Nix package manager with a daemon.
sh <(curl -L https://nixos.org/nix/install) --daemon
When you run the command above, you will see a brief description of what the Nix package manager can do on your computer, what it will install during the initial setup process, etc. Press the Y key to continue.
When you press Y, it will show you what the installation tool will do. Read it. Once you’ve read it, press the Y key to confirm you wish to continue.
The Nix installation tool will ask for sudo permissions once told to continue. Running the Nix package manager in daemon mode needs sudo access. To give the Nix package manager access to sudo, press the Y key next to “Can I use sudo?”
When you give the installer sudo access, it will set itself up on your computer. The installation will not take long. When it is complete, you will automatically be dropped into the “nix-shell,” which is used to install packages.
Configuring the Nix package manager
Before using the Nix package manager, you must download the latest channels. Channels provide software to the Nix package manager, allowing you to install it easily.
To update the channels, open up a terminal window. You can open a terminal window by pressing Ctrl + Alt + T on the keyboard. Or, search for “Terminal” in the app menu to launch it.
Once the terminal window is open, you can use the nix-channel –update command. This command will grab all channels for the Nix package manager and unpack them. Additionally, if there are any package updates, it will pull those down too.
nix-channel --update
When your channels are configured, you can run the nix-env -qa command to view available packages.
nix-env -qa
You can save available packages to a text file later with the following command.
nix-env -qa > nix-pkgs.txt
How to use the Nix package manager to install apps
You will need to search for a package to install software with the Nix package manager on your Linux system. Head over to the Nix package search web page. Then, follow the steps below.
- Find the search for packages box and type in the app you wish to install. For example, to install Vim, search for “vim.” Then, press the enter key to view the search results.
- Look through the search results for the package you wish to install and select it with the mouse. The package details will appear when you select it in the search results.
- When the search results reveal the package details, locate the “nix-env” section, and click on it with the mouse. Then, find “On Non-NixOS” and copy the command to the clipboard.
- Once you’ve copied your command to the clipboard, paste it into the terminal to install your app. For example, to install Vim, paste this command.
nix-env -iA nixpkgs.vim
Once you’ve installed your program, you can launch it from the terminal. Understand Nix packages will not appear with application icons in the app menu. Instead, you must launch them from the terminal directly.
For example, run the following command in a terminal window to launch the vim app.
vim