Update fails with "Permission denied"

According to a comment in issue #6007 the “Too many open files” problem was addressed in release 2.24.5.

I have release 2.24.2 installed as a single-user on Ubuntu 24.04. Following the update instructions I get the result:

$ nix-env --install --file '<nixpkgs>' --attr nix cacert -I nixpkgs=channel:nixpkgs-unstable
unpacking 'https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz' into the Git cache...
replacing old 'nix-2.24.2'
installing 'nix-2.18.5'
installing 'nss-cacert-3.101.1'
error: opening lock file '/nix/store/r2n18r6imwz1n2bb9yvlkbkdykq43yr2-user-environment.lock': Permission denied

nix-env is not available to root (as I understand it because this is a single-user install) so no point in using sudo. Do I need to change permissions on the .lock file referred in the message? Or something else?

Thank you.

P.S.: lateral question, but why is the upgrade saying it is installing release 2.18.5?

The Ubuntu man pages provide a different method to update nix:

nix upgrade-nix

That functions correctly. Apparently the nix-env --install formulation is not operational on Ubuntu. However upgrade-nix installs the latest stable, currently 2.18.5 (answering my second question).

Luckily there is an earlier thread with a solution to the exact question of installing the latest unstable release.