BACK TO THE HOMEPAGE

Apr 09, 2025 2 min read

Nix Package Manager Housekeeping

How to clean up a Nix environment on (Debian Bookworm).

In the blog post Getting started with Nix Package Manager we covered how to install Nix. A quick follow up on that post to discuss how to clean up the environment.

The more you use Nix, the more relevant this post will be. So I separated out the details for the time you need to quickly remove the cache on your machine.

Nix Upgrade

Nix upgrades can be done from the command line.

  1. Change to root account

    NODE_TYPE // bash
    sudo su
  2. Perform an upgrade

    NODE_TYPE // bash
    nix upgrade-nix

    You may also want to do some package management/housekeeping at this point…

  3. Return to the normal user

    NODE_TYPE // bash
    exit

Nix Channel Upgrade

If you find you have an old package running. Refresh to the latest versions.

  1. Update the current channel

    NODE_TYPE // bash
    nix-channel --update
  2. Update the packages using the new channel

    NODE_TYPE // bash
    nix-env -u

Nix Housekeeping

Nix will store the packages ready for the next run. Lets get rid of this cache.

  1. Use the nix-collect-garbage command
    NODE_TYPE // bash
    nix-collect-garbage

Optionally you can remove with a deep clean.

  1. If you want a deep clean you can also append the -d parameter The -d parameter means to perform a deep clean, i.e. remove anything not being used.

    NODE_TYPE // bash
    nix-collect-garbage -d