LoginSignup
2
1

More than 1 year has passed since last update.

【Rust】Ubuntu20.04のRustプログラム言語の環境構築

Last updated at Posted at 2022-10-03

はじめに

本記事は、Ubuntu20.04環境におけるRustのインストールを行う。
Rustのソースコードが実行可能な環境を整備する。

Rustのインストール(環境構築)

  • 実行環境
    • OS : Ubuntu20.04.4 LTS

以下の公式のインストール方法を参考にインストールを行う。

Rustのインストール
@username:~$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
terminal_出力
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 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: 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を入力(デフォルト)

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 YYYY-MM-DD, rust version 1.61.0 (fe5b13d68 YYYY-MM-DD)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 19.7 MiB /  19.7 MiB (100 %)  11.2 MiB/s in  2s ETA:  0s
info: downloading component 'rust-std'
 26.9 MiB /  26.9 MiB (100 %)  11.2 MiB/s in  2s ETA:  0s
info: downloading component 'rustc'
 55.4 MiB /  55.4 MiB (100 %)  10.8 MiB/s in  5s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 19.7 MiB /  19.7 MiB (100 %)   8.7 MiB/s in  2s ETA:  0s
info: installing component 'rust-std'
 26.9 MiB /  26.9 MiB (100 %)  11.4 MiB/s in  3s ETA:  0s
info: installing component 'rustc'
 55.4 MiB /  55.4 MiB (100 %)  13.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.61.0 (fe5b13d68 YYYY-MM-DD)


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

Versionの確認(正しくインストールができたかの確認)
@username:~$ rustc --version
rustc 1.64.0 (a55dd71d5 YYYY-MM-DD)

 
Versionの確認がうまくできない場合はPATH設定を行う。
 

@username:~$ cat $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
@username:~$ source $HOME/.cargo/env

 
改めてバージョン確認
 

正常な出力
@username:~$ rustc --version
rustc 1.64.0 (a55dd71d5 YYYY-MM-DD)

おわりに

RustのUbuntu20.04にRustをインストールしました。
特に問題なく環境構築を行いました。躓いた点としては、PATHの設定を行っていないとうまく実行できない点です。公式では紹介されていないです。もしうまく実行できなくて躓いている場合は、PATHの設定を確認してみてください。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1