Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are modules installed by Cargo stored in a Rust project?

In NodeJS, all the packages installed by NPM are stored in the node_modules/ directory. Is there any such directory in Rust? Are the crates installed somewhere globally?

like image 383
sidoshi Avatar asked Apr 15 '18 17:04

sidoshi


People also ask

Where is Rust Cargo stored?

The home crate provides an API for getting this location if you need this information inside your Rust crate. By default, the Cargo home is located in $HOME/. cargo/ .

Where does Cargo build put binaries?

The . cargo/bin directory of your home directory is the default location of Rust binaries. Not only the official binaries like rustup , rustc , cargo , rustfmt , rustdoc , rls and also the binaries you can install via cargo install command, will be stored in this directory.

How does Cargo work Rust?

Cargo is the Rust package manager. Cargo downloads your Rust package's dependencies, compiles your packages, makes distributable packages, and uploads them to crates.io, the Rust community's package registry.

What are modules in Rust?

Rust provides a powerful module system that can be used to hierarchically split code in logical units (modules), and manage visibility (public/private) between them. A module is a collection of items: functions, structs, traits, impl blocks, and even other modules.


1 Answers

Crates are installed globally for the current user, not per project. Currently, they are stored in <user directory>/.cargo/registry.

  • Mac: /Users/<username>/.cargo/registry
  • Or, in general on Mac, Linux & Unix: $HOME/.cargo/registry
  • Windows 10: \Users\<username>\.cargo\registry

There is an RFC in progress to standardise this, and use the location that users of each platform would more likely expect.

See also:

  • How can the location of Cargo's configuration directory be overridden?
  • Where does Cargo put the git requirements?
like image 171
Peter Hall Avatar answered Oct 26 '22 15:10

Peter Hall