Rustのインストールにはrustupをもちいることが推奨されている12。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shinfo: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/Users/DUMMY/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
/Users/DUMMY/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/Users/DUMMY/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/Users/DUMMY/.profile
/Users/DUMMY/.bash_profile
/Users/DUMMY/.zshenv
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 (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>
info: profile set to 'default'
info: default host triple is x86_64-apple-darwin
info: syncing channel updates for 'stable-x86_64-apple-darwin'
info: latest update on 2023-08-24, rust version 1.72.0 (5680fa18f 2023-08-23)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
13.7 MiB / 13.7 MiB (100 %) 10.4 MiB/s in 1s ETA: 0s
info: downloading component 'rust-std'
25.0 MiB / 25.0 MiB (100 %) 7.5 MiB/s in 3s ETA: 0s
info: downloading component 'rustc'
55.5 MiB / 55.5 MiB (100 %) 10.6 MiB/s in 5s ETA: 0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
13.7 MiB / 13.7 MiB (100 %) 3.1 MiB/s in 3s ETA: 0s
info: installing component 'rust-std'
25.0 MiB / 25.0 MiB (100 %) 12.4 MiB/s in 2s ETA: 0s
info: installing component 'rustc'
55.5 MiB / 55.5 MiB (100 %) 14.4 MiB/s in 3s ETA: 0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-apple-darwin'
stable-x86_64-apple-darwin installed - rustc 1.72.0 (5680fa18f 2023-08-23)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, run:
source "$HOME/.cargo/env"
$HOME/.rustup配下にダウンロードしたファイルなどが保存され、$HOME/.cargo配下にcargoの環境が作られる。$HOME/.bash_profileなどにはcargoの設定を読み込むための設定が追加される。
source "$HOME/.cargo/env"
$HOME/.cargo/env内は次のように記述されている。
#!/bin/sh
# rustup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
*:"$HOME/.cargo/bin":*)
;;
*)
# Prepending path in case a system-installed rustc needs to be overridden
export PATH="$HOME/.cargo/bin:$PATH"
;;
esac
やっていることは単純でPATHの中に$HOME/.cargo/bin(cargoが準備したコマンドを配置しているディレクトリ)が設定されていない場合、その設定をPATHに追加している。