在Ubuntu上安裝和配置Rust編程語言環境是一個相對簡單的過程。以下是詳細的步驟:
sudo apt update
sudo apt install curl build-essential gcc make
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
按照提示選擇安裝類型(通常是選項1:腳本完成安裝),然后關閉終端并重新打開,以應用環境變量更改。
rustc --version
你應該能看到Rust編譯器的版本信息。
如果你在中國大陸地區,可能會遇到官方源速度慢的問題??梢酝ㄟ^修改~/.cargo/config.toml
文件來配置國內的鏡像源。例如,使用清華大學大學的鏡像源:
[registries]
crates-io = { index = "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index" }
Cargo是Rust的包管理器和構建工具。安裝Rust時,Cargo通常會自動安裝。你可以通過以下命令驗證Cargo是否安裝成功:
cargo --version
cargo new hello_world
cd hello_world
cargo build
cargo run
rustup update
cargo install cargo
請注意,cargo install cargo
命令會安裝最新版本的Cargo,這可能會覆蓋你之前安裝的版本。
以上步驟應該能夠幫助你在Ubuntu上成功安裝和配置Rust環境。如果在安裝過程中遇到問題,可以參考Rust官方文檔或相關社區論壇尋求幫助。