cargo install
从Rust 1.5开始,您可以使用cargo install
在系统上安装binary crates.您可以从以下位置安装 crate :
- crate .io(默认值),使用
cargo install crate_name
- 任何git存储库,使用
cargo install --git repository_url
- 任何目录,使用
cargo install --path /path/to/crate
前两个选项还可以指定:
- 用 crate .io,可以使用
--vers
指定 crate 版本.
- 使用git存储库,可以使用
--branch
来设置要从中安装的分支,使用--tag
来指定要使用的标记版本,使用--rev
来从特定提交进行构建.
Installation location:
可以通过以下方法将cargo install
配置为安装在自定义目录中,按优先顺序(最高优先):
- 通过
--root /path/to/directory
(这条路径是相对的)
- 通过设置
$CARGO_INSTALL_ROOT
环境变量
- 通过设置
install.root
configuration key
- 通过设置
$CARGO_HOME
环境变量(这将影响cargo install
的安装目录)
如果没有上述内容,cargo将在~/.cargo/bin
个集装箱中安装 crate .
在上述所有情况下,输出文件实际上都将被放置在bin
子目录中(例如,--root /path/to/directory
将实际将ouput放置在/path/to/directory/bin
中).
Uninstallation
cargo uninstall
可用于移除之前安装的 crate .如果安装了多个同名 crate ,则可以指定--root
以仅删除该目录中的版本.
Example: I want to use rustfmt:
我可以在 crate 上使用这个版本.io:
我喜欢使用原始版本:
cargo install rustfmt --vers 0.0.1
我希望它安装在/opt/rust_crates
:
cargo install rustfmt --root /opt/rust_crates
我真的需要使用最前沿的版本:
cargo install --git https://github.com/rust-lang-nursery/rustfmt.git
最新的提交有一个bug!
cargo install --git https://github.com/rust-lang-nursery/rustfmt.git --rev f5bd7b76e0185e8dd37ae6b1b5fb5e11187f0b8c
我真的很想要使用git子模块作为其依赖项的版本:
cargo install --git https://github.com/rust-lang-nursery/rustfmt.git --branch submods
我克隆了它并做了一些编辑:
cargo install --path ~/my_rustfmt
实际上,我坚持完全手动进行格式化: