Nix - The Purely Functional Package Manager for Linux
Last Updated :
07 Mar, 2025
Nix is a purely functional package manager for Linux, that serves to provide a purely functional approach to any system's software package management. Due to its functional and declarative approach, it is lauded for its capacity to:
- Support the installation of multiple versions of a given package.
- Enable atomic upgrades and rollbacks of a given package.
Drawbacks of Traditional Package Managers and how Nix Solves these Problems
- Dependency resolution: Traditional package managers often struggle with resolving dependencies, leading to issues such as dependency hell. In contrast, Nix uses a functional approach to package management, which allows it to automatically resolve dependencies and avoid conflicts.
- Reproducibility: Traditional package managers can be difficult to use for reproducible builds, as they do not always provide a clear way to specify the exact versions of packages that should be used. Nix, on the other hand, allows users to specify exact versions of packages, making it easier to reproduce builds.
- Rollback: Traditional package managers do not have an easy way to roll back to a previous version of a package. Nix, on the other hand, allows users to switch between different versions of packages easily, making it easier to roll back if necessary.
- Multi-user support: Traditional package managers are not designed to support multiple users on a single system, which can lead to conflicts and permission issues. Nix, on the other hand, has built-in support for multiple users, allowing them to have separate package environments without affecting each other.
- Complexity: Traditional package managers can be complex to use, particularly for users who are not familiar with command-line interfaces. Nix, on the other hand, has a simpler user interface and is easier for new users to learn.
Features of Nix
One of the key features of Nix is its support for declarative configuration. This means that users can specify the packages and dependencies that they want to install on their system, and Nix will automatically handle the process of installing and configuring those packages. This makes it easier for users to manage their system and ensures that all necessary dependencies are installed and configured correctly.
In addition to its declarative configuration support, Nix also offers atomic upgrades and rollbacks. This means that when a package is upgraded or installed, Nix creates a new configuration for the system that includes the updated package. If the upgrade causes problems in the system, users can easily roll back to the previous configuration using Nix. This helps to reduce the risk of breakages and makes it easier to recover from problems.
Another key feature of Nix is its support for multiple versions of packages on the same system. This means that users can install and use multiple versions of the same package on their system, which can be useful for testing or development purposes. Nix makes it easy to switch between different versions of a package and ensures that all necessary dependencies are installed and configured correctly.
Installation and Usage of Nix
Nix can be installed on Linux distributions using the following procedure:
Open the shell, and use curl to run the installation script:
For single-user installation:
$ sh <(curl -L https://nixos.org/nix/install) --no-daemon
For multi-user installation:
$ sh <(curl -L https://nixos.org/nix/install) --daemon
The installation script will then proceed to download and install Nix on your system. This process may take several minutes to complete. To ensure that the necessary environment variables are set, either log in again, or type
./home/your_user_name/.nix-profile/etc/profile.d/nix.sh
You can then use the nix-env command to manage packages on your system.
Managing Profiles
Nix uses profiles to manage packages. To list your available profiles, use the command nix-env --list-generations. To switch to a different profile, use the command nix-env --switch-generation <generation>. For example:
nix-env --list-generations
nix-env --switch-generation 2
nix-env --switch-generation 3
Managing Channels
Nix uses channels to manage package repositories. To list your available channels, use the command nix-channel --list. To add a new channel, use the command nix-channel --add <channel-url>.
For example:
nix-channel --list
Searching for a Package
To search for a package, you can use the nix-env -qa command followed by the package name. For example:
nix-env -qa firefox
Installing a package
To install a package, you can use the nix-env -i command followed by the package name. For example:
nix-env -i firefox
Upgrading packages
To upgrade a package, use the command nix-env -u <package-name>.
For example:
nix-env -u firefox
As the firefox package had just been installed, there was no upgrade.
Rolling back packages
To roll back to a previous version of a package, use the command nix-env --rollback. This will roll back to the previous generation of packages. For example:
nix-env --rollback
Uninstalling packages
To uninstall a package, use the command nix-env -e followed by the package name. For example:
nix-env -e firefox
Garbage removal
To remove old or unused packages, use the command nix-collect-garbage:
nix-collect-garbage
Uninstalling Nix
Nix can be uninstalled from a Linux system using the following command:
sudo apt-get remove nix
Conclusion
Nix is a purely functional package manager with various features, such as atomic upgrades/rollbacks and support for multiple installations. It can be easily installed on a Linux system by downloading the Nix installation script and running it on the system. Once Nix is installed, users can use the nix-env command to manage packages on their system.
Similar Reads
How to Install a New Package Manager in Linux
Linux offers several package managers for software installation, updates, and maintenance. In Linux, every distribution comes with a package manager by default. The Debian distribution comes with APT(Advanced Package Tool), Red Hat, and its derivatives such as CentOS and Fedora use YUM package manag
4 min read
sysget - Front-End For Every Package Manager in Linux
There are lots of package managers for various Linux distros, for example, apt (Ubuntu), yum (legacy Fedora), dnf (Fedora) but remembering them all is quite a headache. So for that reason, there is a utility called sysget, which is a front-end for every package manager in Unix-like operating systems
2 min read
How to Manage Packages in Red Hat-based Linux?
Package management tools like dnf (Dandified YUM) or yum (Yellowdog Updater Modified) are used to manage packages on Red Hat-based Linux systems. These programs support the installation, removal, and upgrading of software packages on your computer. Typical package management tasks include the follow
4 min read
How to manage the packages in Node.js project ?
Node.js is an open-source, cross-platform, back-end JavaScript runtime environment built on the V8 engine and executes the JavaScript code outside the browser. When working on a project in Node.js, you may write code to achieve a specific functionality or to solve a particular problem. There are som
6 min read
Linux - Installing PIP to Manage Python Packages
Python is the most popular language for a decade, and we all know that python had a huge support of libraries that are used in different sectors of Software Engineering. Meanwhile, PIP also getting its fame along with python in Linux and developers community.PIP is a package manager for python in ha
3 min read
How to Manage Debian Packages in Linux?
Debian, one of the oldest and most respected Linux distributions, is renowned for its stability, security, and robust package management system. Managing Debian packages effectively is crucial for maintaining a healthy and well-functioning Linux system. In this comprehensive guide, we will explore e
9 min read
How to Use Package Managers in Linux? APT and YUM
Package managers like APT and YUM are essential tools for managing software on Linux systems. They allow you to install, update, and remove packages easily, ensuring your system is up-to-date and secure. APT is commonly used in Debian-based distributions like Ubuntu, while YUM is used in Red Hat-bas
5 min read
YUM Commands for Linux Package Management
If you are a Linux user or system administrator, chances are you've come across YUM (Yellowdog Updater, Modified) at some point in your journey. YUM is a powerful package management tool that simplifies the process of installing, updating, and managing software on Red Hat-based Linux distributions l
5 min read
How to Install RPM Packages on Linux?
Red Hat Package Manager or RPM is a free and open-source package management system for Linux. The RPM files use the .rpm file format. Â RPM package manager was created to use with Red Hat Linux, but now it is supported by multiple Linux distributions such as Fedora, OpenSUSE, Ubuntu, etc.RPM packages
3 min read
Need of Package Managers in Developer's Life
Ever Since Mankind started to program things, they started distributing them to various firms, individuals, etc. One had to install software on its own using the README file, which is tedious and time-consuming work. There comes the need to use the package managers. Package managers speed up the dev
3 min read