Rustのインストール方法。 Rustの公式ページにアクセスすると、使用しているOS用のインストール方法が表示されます。 その指示に沿ってインストールします。
Linux
Linuxの場合は、以下を実行します。 Rustは、ユーザー単位でインストールできますので、root権限にならずに使用するユーザーのまま実行します。
curl https://sh.rustup.rs -sSf | sh
例
$ curl https://sh.rustup.rs -sSf | sh info: downloading installer Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure 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: /home/vagrant/.rustup This can be modified with the RUSTUP_HOME environment variable. The Cargo home directory located at: /home/vagrant/.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: /home/vagrant/.cargo/bin This path will then be added to your PATH environment variable by modifying the profile files located at: /home/vagrant/.profile /home/vagrant/.bash_profile /home/vagrant/.bashrc You can uninstall at any time with rustup self uninstall and these changes will be reverted. Current installation options: default host triple: x86_64-unknown-linux-gnu default toolchain: stable (default) profile: default modify PATH variable: yes 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >デフォルトインストール、カスタムインストール、またはキャンセルから選択します。 ここではデフォルトインストールの "1" を入力しました。
info: profile set to 'default' info: default host triple is x86_64-unknown-linux-gnu info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: latest update on 2021-05-10, rust version 1.52.1 (9bc8c42bb 2021-05-09) info: downloading component 'cargo' info: downloading component 'clippy' info: downloading component 'rust-docs' info: downloading component 'rust-std' 24.1 MiB / 24.1 MiB (100 %) 10.7 MiB/s in 2s ETA: 0s info: downloading component 'rustc' 48.4 MiB / 48.4 MiB (100 %) 5.5 MiB/s in 12s ETA: 0s info: downloading component 'rustfmt' info: installing component 'cargo' info: using up to 500.0 MiB of RAM to unpack components 6.0 MiB / 6.0 MiB (100 %) 2.8 MiB/s in 2s ETA: 0s info: installing component 'clippy' info: installing component 'rust-docs' 15.3 MiB / 15.3 MiB (100 %) 2.4 MiB/s in 5s ETA: 0s info: installing component 'rust-std' 24.1 MiB / 24.1 MiB (100 %) 4.3 MiB/s in 5s ETA: 0s info: installing component 'rustc' 48.4 MiB / 48.4 MiB (100 %) 3.1 MiB/s in 13s ETA: 0s info: installing component 'rustfmt' info: default toolchain set to 'stable-x86_64-unknown-linux-gnu' stable-x86_64-unknown-linux-gnu installed - rustc 1.52.1 (9bc8c42bb 2021-05-09) 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
インストールが完了したら、インストールメッセージに沿って以下を実行します。
source $HOME/.cargo/envすると、cargoコマンドが使用できるようになります。
$ which cargo ~/.cargo/bin/cargo
CentOS 7・環境設定
CentOS 7の場合、インストール後 ~/.bashrc に以下が追加されています。 そのため、インストール後は、ログイン時にRust用環境が設定されるようになります。
# User specific aliases and functions . "$HOME/.cargo/env"