Ubuntu 22.04にRust1.64をインストールする

環境
OSバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"

操作方法
1.gccをインストールします

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

2.Rustインストール
curlをインストールします

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

curlを使ってRustをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# curl https://sh.rustup.rs -sSf | sh
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
# curl https://sh.rustup.rs -sSf | sh 略 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
# curl https://sh.rustup.rs -sSf | sh
略
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」のdefaultを選択します。

3.「Rust is installed now. Great!」メッセージが表示されればインストール完了です。
環境PATHを通します
# source $HOME/.cargo/env

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# rustc --version
rustc 1.64.0 (a55dd71d5 2022-09-19)
# rustc --version rustc 1.64.0 (a55dd71d5 2022-09-19)
# rustc --version
rustc 1.64.0 (a55dd71d5 2022-09-19)

5.動作確認
# nano hello.rs
以下のコードを記述します

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

ファイルを実行します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# rustc test.rs
# ./test
Hello, world
# rustc test.rs # ./test Hello, world
# rustc test.rs
# ./test
Hello, world

 

Ubuntu 22.04

Posted by arkgame