Think Twice
IT技術メモ | Rustのメモ
Created: 2022-09-28 / Updated: 2022-09-28

Windows環境(WSL)にRustをインストール


目次


インストール

Rustのダウンロードとインストール

Copy
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | 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.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/fumo/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/fumo/.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/fumo/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/fumo/.profile
  /home/fumo/.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と打ってEnter。ちなみに、fumoって部分は私のユーザ名です。

Copy
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 2022-09-22, rust version 1.64.0 (a55dd71d5 2022-09-19)
info: downloading component 'cargo'
  6.4 MiB /   6.4 MiB (100 %)   1.2 MiB/s in  5s ETA:  0s
info: downloading component 'clippy'
  2.8 MiB /   2.8 MiB (100 %)   1.1 MiB/s in  2s ETA:  0s
info: downloading component 'rust-docs'
 18.8 MiB /  18.8 MiB (100 %)   1.1 MiB/s in 16s ETA:  0s
info: downloading component 'rust-std'
 27.4 MiB /  27.4 MiB (100 %)   1.2 MiB/s in 26s ETA:  0s
info: downloading component 'rustc'
 54.2 MiB /  54.2 MiB (100 %)   1.1 MiB/s in 51s ETA:  0s
info: downloading component 'rustfmt'
  4.3 MiB /   4.3 MiB (100 %) 849.2 KiB/s in  5s ETA:  0s
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 18.8 MiB /  18.8 MiB (100 %)   6.2 MiB/s in  2s ETA:  0s
info: installing component 'rust-std'
 27.4 MiB /  27.4 MiB (100 %)  10.3 MiB/s in  2s ETA:  0s
info: installing component 'rustc'
 54.2 MiB /  54.2 MiB (100 %)  12.6 MiB/s in  4s 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.64.0 (a55dd71d5 2022-09-19)


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"

終わった。

rustc(Rustのコンパイラ)やcargo(Rustのツールチェーン)へ実行パスを通す

Copy
$ source "$HOME/.cargo/env"

ターミナルを閉じてもパスが通るよう、.bashrcなどに以下行を追加

Copy
export PATH="$HOME/.cargo/bin:$PATH"

動作確認

バージョン確認

rustcとcargoコマンド
Copy
$ rustc -V
rustc 1.64.0 (a55dd71d5 2022-09-19)
$ cargo -V
cargo 1.64.0 (387270bc7 2022-09-16)

参考

参考書籍

参考サイト