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.
-
Change to
rootaccountNODE_TYPE // bashsudo su -
Perform an upgrade
NODE_TYPE // bashnix upgrade-nixYou may also want to do some package management/housekeeping at this point…
-
Return to the normal user
NODE_TYPE // bashexit
Nix Channel Upgrade
If you find you have an old package running. Refresh to the latest versions.
-
Update the current channel
NODE_TYPE // bashnix-channel --update -
Update the packages using the new channel
NODE_TYPE // bashnix-env -u
Nix Housekeeping
Nix will store the packages ready for the next run. Lets get rid of this cache.
- Use the nix-collect-garbage command
NODE_TYPE // bash
nix-collect-garbage
Optionally you can remove with a deep clean.
-
If you want a deep clean you can also append the
-dparameter The-dparameter means to perform a deep clean, i.e. remove anything not being used.NODE_TYPE // bashnix-collect-garbage -d