要在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上成功构建并运行。如果有任何问题,请检查错误信息并相应地进行调试。