getting error when doing cargo build

error: failed to load source for a dependency on rand

Caused by:
Unable to update registry https://github.com/rust-lang/crates.io-index

Caused by:
failed to rename lockfile to '/root/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/config': 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.