Using same dependencies in different projects

I have added "rand" dependency in one project.

The dependency got added from relevant website and project got complied and execution of the program was fine.

When have added "rand" dependency in next project, cargo again looked for website.

Is there a common repository where dependencies can be stored so that different projects can use it without having to get it again their websites?

If yes then, what is the procedure to do so?

Yes you can do it if you are using library which you use before and have same version number

try this
cargo install --offline
or
cargo build --offline

use --offline flag : Run without accessing the network

**

I have tried this command "cargo build --offline" and got the following messages

**
Compiling getrandom v0.2.2
Compiling cfg-if v1.0.0
Compiling ppv-lite86 v0.2.10
Compiling rand_core v0.6.2
Compiling rand_chacha v0.3.0
Compiling rand v0.8.3
Compiling KA_Test_rustIProject3 v0.1.0 (F:\KA_IdeaProjects\KA_Test_rustIProject3)
warning: crate KA_Test_rustIProject3 should have a snake case name
|
= note: #[warn(non_snake_case)] on by default
= help: convert the identifier to snake case: ka_test_rust_iproject3

warning: 1 warning emitted

Finished dev [unoptimized + debuginfo] target(s) in 23.59s

** It compiled correctly. Finally entered this command "cargo run"

strong text

**

Compiling KA_Test_rustIProject3 v0.1.0 (F:\KA_IdeaProjects\KA_Test_rustIProject3)
warning: crate KA_Test_rustIProject3 should have a snake case name
|
= note: #[warn(non_snake_case)] on by default
= help: convert the identifier to snake case: ka_test_rust_iproject3

warning: 1 warning emitted

Finished dev [unoptimized + debuginfo] target(s) in 2.26s
 Running `target\debug\KA_Test_rustIProject3.exe`

Hello, world!
The random number is: 69

**

The program worked correctly. Thanks for guidance. When do we use this command "cargo install --offline"??

**

They're cached in ~/.cargo/registry/cache folder. It's not being downloaded more than once.

Cargo will compile each dependency separately for each project. Currently there's no good solution to this, existing half-solutions (like changes of target dir) are not good.

If it's a very big issue for you, you can try installing sccache, but IMHO it's not worth it unless you have hundreds of projects with thousands of dependencies.

**

What does sccache do??

**

It's a wrapper around rust compiler that creates an additional shared cache, which it can store on disk or a network storage.

> OK. Thank you!