鉢本 一二のブログ

Rustのインストール方法 Linuxの場合

作成日 :
更新日 :
local_offer Rust

Rustのインストール方法をメモ。
今回インストールされたRustのバージョンは、rustc 1.38.0 (625451e37 2019-09-23)

まず、コマンドを実行。

$ curl https://sh.rustup.rs -sSf | sh

コマンドを実行すると、インストールが始まる。
インストールの方法を入力する必要がある。とりあえず、1を選択。

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:

  /home/local/.cargo/bin

This can be modified with the CARGO_HOME environment variable.

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

  /home/local/.rustup

This can be modified with the RUSTUP_HOME environment variable.

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

  /home/local/.profile

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
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1 <--- ここで入力が発生。

info: profile set to 'default'
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2019-09-26, rust version 1.38.0 (625451e37 2019-09-23)
info: downloading component 'cargo'
  4.7 MiB /   4.7 MiB (100 %)   4.2 MiB/s in  1s ETA:  0s
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 11.7 MiB /  11.7 MiB (100 %)   5.2 MiB/s in  2s ETA:  0s
info: downloading component 'rust-std'
173.3 MiB / 173.3 MiB (100 %)   4.0 MiB/s in 42s ETA:  0s
info: downloading component 'rustc'
 66.1 MiB /  66.1 MiB (100 %)   4.7 MiB/s in 14s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 11.7 MiB /  11.7 MiB (100 %) 745.6 KiB/s in  9s ETA:  0s
info: installing component 'rust-std'
173.3 MiB / 173.3 MiB (100 %)  22.8 MiB/s in  8s ETA:  0s
info: installing component 'rustc'
 66.1 MiB /  66.1 MiB (100 %)  12.2 MiB/s in  5s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable'

  stable installed - rustc 1.38.0 (625451e37 2019-09-23)


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

インストールの最後の出力にもあるが、Rustは$HOME/.cargoにインストールされている。
$HOME/.cargo/envの内容が、Rustのパスを設定がされている内容となっている。
envファイルを使ってを起動時にRustを実行できるようにするため、$HOME/.bashrcを編集する。
.bashrcを開き、一番下の行に次の文を追加。

source $HOME/.cargo/env

.bashrcを読み込む。

$ source $HOME/.bashrc

パスがちゃんと設定されているか確認のため、以下のコマンドを実行。

$ rustc --version

次のようにバージョン情報が出力されれば、OK。

rustc 1.38.0 (625451e37 2019-09-23)