要在Ubuntu上部署運行Rust程序,請按照以下步驟操作:
sudo apt update
sudo apt install curl build-essential gcc make
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustc --version
cd /path/to/your/rust/project
cargo build
這會生成一個可執行文件,通常位于target/debug/
目錄下。
./target/debug/your_executable_name
將your_executable_name
替換為你的項目生成的可執行文件名。
為了加快依賴包的下載速度,可以配置Cargo使用國內的鏡像源:
~/.cargo/config.toml
中添加鏡像配置:[registries]
ustc = { index = "https://mirrors.ustc.edu.cn/crates.io-index/" }
或者覆蓋默認的鏡像地址:
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
cargo update
完成以上步驟后,你的Rust程序應該可以在Ubuntu上成功構建并運行。如果有任何問題,請檢查錯誤信息并相應地進行調試。