Debian 11.2にRustをインストールする

環境
# cat /etc/debian_version
11.2

Rustをインストールする方法

1.パッケージをアップデートします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt update
# sudo apt update
# sudo apt update

2.依存パッケージをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt install curl build-essential gcc make -y
# sudo apt install curl build-essential gcc make -y
# sudo apt install curl build-essential gcc make -y

3.Rustをダウンロードしてインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# wget -qO - https://sh.rustup.rs | sudo RUSTUP_HOME=/opt/rust CARGO_HOME=/opt/rust sh -s -- --no-modify-path -y
Rust is installed now. Great!
To get started you need Cargo's bin directory (/opt/rust/bin) in your PATH
environment variable. This has not been done automatically.
To configure your current shell, run:
source /opt/rust/env
# wget -qO - https://sh.rustup.rs | sudo RUSTUP_HOME=/opt/rust CARGO_HOME=/opt/rust sh -s -- --no-modify-path -y 略 Rust is installed now. Great! To get started you need Cargo's bin directory (/opt/rust/bin) in your PATH environment variable. This has not been done automatically. To configure your current shell, run: source /opt/rust/env
# wget -qO - https://sh.rustup.rs | sudo RUSTUP_HOME=/opt/rust CARGO_HOME=/opt/rust sh -s -- --no-modify-path -y
略
Rust is installed now. Great!

To get started you need Cargo's bin directory (/opt/rust/bin) in your PATH
environment variable. This has not been done automatically.

To configure your current shell, run:
source /opt/rust/env

4.環境変数を追加します

RUSTUPのホーム環境を追加

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# echo 'export RUSTUP_HOME=/opt/rust' | sudo tee -a /etc/profile.d/rust.sh
export RUSTUP_HOME=/opt/rust
# echo 'export RUSTUP_HOME=/opt/rust' | sudo tee -a /etc/profile.d/rust.sh export RUSTUP_HOME=/opt/rust
# echo 'export RUSTUP_HOME=/opt/rust' | sudo tee -a /etc/profile.d/rust.sh
export RUSTUP_HOME=/opt/rust

Rustの環境パスを追加

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# echo 'export PATH=$PATH:/opt/rust/bin' | sudo tee -a /etc/profile.d/rust.sh
export PATH=$PATH:/opt/rust/bin
# echo 'export PATH=$PATH:/opt/rust/bin' | sudo tee -a /etc/profile.d/rust.sh export PATH=$PATH:/opt/rust/bin
# echo 'export PATH=$PATH:/opt/rust/bin' | sudo tee -a /etc/profile.d/rust.sh
export PATH=$PATH:/opt/rust/bin

現在のシェルプロファイルを再読み込みします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# source /etc/profile
# source /etc/profile
# source /etc/profile

環境変数を確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# echo $RUSTUP_HOME
/opt/rust
# echo $RUSTUP_HOME /opt/rust
# echo $RUSTUP_HOME
/opt/rust
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rust/bin
# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rust/bin
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rust/bin

5.バージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# rustc --version
rustc 1.59.0 (9d1b2106e 2022-02-23)
# rustc --version rustc 1.59.0 (9d1b2106e 2022-02-23)
# rustc --version
rustc 1.59.0 (9d1b2106e 2022-02-23)

6.bashのrustupコマンド設定を行います

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# rustup completions bash > /usr/share/bash-completion/completions/rustup
# rustup completions bash > /usr/share/bash-completion/completions/rustup
# rustup completions bash > /usr/share/bash-completion/completions/rustup

設定内容をリロードします
# source /etc/profile.d/bash_completion.sh
コマンドの確認
# rustup TAB

7.Rustプロジェクトの設定

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# mkdir -p ~/rustpro
# cd ~/rustpro
# mkdir -p ~/rustpro # cd ~/rustpro
# mkdir -p ~/rustpro
# cd ~/rustpro

Rustスクリプトを作成します。
# nano hello-world.rs
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fn main() {
println!("Hello World, welcome to Rust.");
}
fn main() { println!("Hello World, welcome to Rust."); }
fn main() {
println!("Hello World, welcome to Rust.");
}

ファイルをコンパイルします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# ./hello-world
Hello World, welcome to Rust.
# ./hello-world Hello World, welcome to Rust.
# ./hello-world
Hello World, welcome to Rust.

 

Debian 11

Posted by arkgame