getting error when doing cargo build

error: failed to load source for a dependency on rand

Caused by:
Unable to update registry

Caused by:
failed to rename lockfile to ‘/root/.cargo/registry/index/’: No such file or directory; class=Os (2)

I’m getting the above error when I put rand as a dependency in cargo.toml

You might have to delete Cargo.lock to get this to work. That’s what fixed a similar issue I experienced a few weeks ago.