Loading...

2023-10-02(月) 15:00

🍓 Ubuntu に Rustをインストールする

RustUbuntu
Ubuntu にRustをインストールする手順を解説します。

目次

前提

この記事では以下を前提としています。

  • Ubuntu 22.04

この記事のゴール

この記事では Ubuntu に Rust をインストールして、Rust のバージョン確認するところまでをゴールとしています。

rustup をインストールする

Rust 公式プロジェクトであるrustupを使用します。

rustup

rustup is an installer for the systems programming language Rust

rustup.rs

rustupは Rust の公式サイトで推奨されている方法になります。

Rust

Rust をインストール

www.rust-lang.org

以下を Ubuntu で実行します。

ターミナル
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

実行結果は以下です。

ターミナル
$ 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/username/.rustup
 
This can be modified with the RUSTUP_HOME environment variable.
 
The Cargo home directory is located at:
 
  /home/username/.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/username/.cargo/bin
 
This path will then be added to your PATH environment variable by
modifying the profile files located at:
 
  /home/username/.profile
  /home/username/.bashrc
 
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
 
Current installation options:
 
 
   default host triple: aarch64-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

上記のように、インストールについての確認が表示されます。

1) Proceed with installation (default)を選択すると、デフォルトのオプションでインストールを進めます。

2) Customize installationを選択すると、インストールについてのオプションを設定できます。

3) Cancel installationを選択すると、インストールをキャンセルできます。

ここでは、デフォルトでインストールを進めるため1を入力します。進めると以下のように表示されます。

ターミナル
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1
 
info: profile set to 'default'
info: default host triple is aarch64-unknown-linux-gnu
info: syncing channel updates for 'stable-aarch64-unknown-linux-gnu'
info: latest update on 2023-10-05, rust version 1.73.0 (cc66ad468 2023-10-03)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
 29.9 MiB /  29.9 MiB (100 %)  17.3 MiB/s in  3s ETA:  0s
info: downloading component 'rustc'
 74.3 MiB /  76.5 MiB ( 97 %)  15.8 MiB/s in  5s ETA:  0s
 
... 省略 ...
 
info: installing component 'rustc'
 76.5 MiB /  76.5 MiB (100 %)   4.9 MiB/s in 17s ETA:  0s
  9 IO-ops /   9 IO-ops (100 %)   4 IOPS in  2s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-aarch64-unknown-linux-gnu'
 
  stable-aarch64-unknown-linux-gnu installed - rustc 1.73.0 (cc66ad468 2023-10-03)
 
 
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"

最後に指示されている通り以下をターミナルで実行します。 以下を実行することで、Rust 公式のパッケージ管理ツールであるcargoコマンドを使用できるようになります。

ターミナル
$ source "$HOME/.cargo/env"

実際にcargoのバージョンを確認してみます。

ターミナル
$ cargo -V
cargo 1.73.0 (9c4383fb5 2023-08-26)

Rust のバージョンを確認してみます。

ターミナル
$ rustc -V
rustc 1.73.0 (cc66ad468 2023-10-03)

これで Rust 環境の構築が完了しました。

アップデート

Rust をアップデートしたい場合は以下を実行します。

ターミナル
$ rustup update

アンインストール

Rust をアンインストールしたい場合は、以下を実行します。

ターミナル
rustup self uninstall

まとめ

Ubuntu に Rust をインストールする手順を解説しました。rustupを使うことで特に問題なくすんなりインストールすることができると思います。