-Z unstable-options

I am new to rust programming. While executing cargo build getting this error

error: the -Z unstable-options flag must also be passed to enable the flag check-cfg

Tried command cargo build -Z unstable-options then also getting the same error.

I think there is something wrong with your installation of rust. Do you have multiple versions installed? Perhaps one from rustup and one from your package manager?

What is the correct way of installation?

I have used rustup for new installation and it is working Thanks

What is the output of cargo --version and rust --version for you? It’s likely there is a version mismatch ~ maybe a newer cargo from rustup tries to call an older rustc from a system package. Depending on your operating system, there’s different ways to re-configure the search path so that e.g. the rustup-installed binaries get priority; though realistically, it might be a good idea anyway to uninstall unnecessarry additional rustc installations if they aren’t needed.

Yes that was the issue, there was a version mismatch. Re- installed using the command curl https://sh.rustup.rs -sSf | sh and it is working.