rustc、cargo、rustup、rustfmtなどのインストール
前回のエントリでは横着してbrew install rustとしたけど、それだといろいろ無いっぽいので、toolchain一式入るように入れ直す。
まずはお掃除
% brew uninstall rust
無いことを確認。
% which rustc % which cargo
公式ドキュメントに従ってインストール
% curl https://sh.rustup.rs -sSf | sh
以下、その出力全文
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust programming
language, and its package manager, Cargo.
It will add the cargo, rustc, rustup and other commands to Cargo's bin
directory, located at:
/Users/otiai10/.cargo/bin
This path will then be added to your PATH environment variable by modifying the
profile files located at:
/Users/otiai10/.profile
/Users/otiai10/.zprofile
You can uninstall at any time with rustup self uninstall and these changes will
be reverted.
Current installation options:
default host triple: x86_64-apple-darwin
default toolchain: stable
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
1
info: syncing channel updates for 'stable-x86_64-apple-darwin'
info: latest update on 2018-02-15, rust version 1.24.0 (4d90ac38c 2018-02-12)
info: downloading component 'rustc'
38.5 MiB / 38.5 MiB (100 %) 27.1 MiB/s ETA: 0 s
info: downloading component 'rust-std'
54.6 MiB / 54.6 MiB (100 %) 29.1 MiB/s ETA: 0 s
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: default toolchain set to 'stable'
stable installed - rustc 1.24.0 (4d90ac38c 2018-02-12)
Rust is installed now. Great!
To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done automatically.
To configure your current shell run source $HOME/.cargo/env
ということで、言われたとおり、$HOME/.cargo/binをPATHに追加する。
% ls $HOME/.cargo/bin cargo cargo-fmt rls rust-gdb rust-lldb rustc rustdoc rustfmt rustup % echo 'export PATH=${HOME}/.cargo/bin:${PATH}' >> ~/.zshrc % source ~/.zshrc % which rustc /Users/otiai10/.cargo/bin/rustc % rustc --version rustc 1.24.0 (4d90ac38c 2018-02-12)
いいですね。
cargo new してみる
% cd ~/proj/rust % cargo new --help % cargo new --bin % cd hello % cargo run Compiling hello v0.1.0 (file:///Users/otiai10/proj/rust/hello) Finished dev [unoptimized + debuginfo] target(s) in 0.39 secs Running `target/debug/hello` Hello, world! %
いい感じに、前回記事の状態を再現できた。
DRY
以下追記 2018/02/27
error: toolchain 'beta-x86_64-apple-darwin' does not have the binary rustfmt
rustfmtが動かんかったので
% rustfmt --version error: toolchain 'beta-x86_64-apple-darwin' does not have the binary `rustfmt` % rustup update # ↓ toolchain install は要りません。 # rustup toolchain install stable-x86_64-apple-darwin % rustup component add rustfmt-preview % rustfmt --version 0.3.8-nightly (346238f 2018-02-04)
はい。