在Debian系统上使用Rust可以分为以下几个步骤:
sudo apt update
sudo apt upgrade -y
sudo apt install curl build-essential gcc make -y
rustup安装Rust:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path -y
这个命令会下载并运行rustup的安装脚本,按照提示操作。通常,rustup会自动将Rust的工具链添加到你的PATH环境变量中。
为了确保环境变量永久生效,可以将以下内容添加到~/.bashrc或~/.profile文件中:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' | sudo tee -a /etc/profile.d/rust.sh
source /etc/profile
安装完成后,可以通过以下命令验证Rust是否安装成功:
rustc --version
cargo --version
如果显示了版本号,说明Rust已经成功安装。
cargo new hello_world
cd hello_world
src/main.rs文件,并输入以下代码:fn main() {
println!("Hello, world!");
}
cargo run
这将编译你的Rust代码并运行生成的可执行文件。如果一切正常,你应该会在终端看到输出:
Compiling hello_world v0.1.0 (/path/to/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 0.34s
Running `target/debug/hello_world`
Hello, world!
cargo build --release
这将在target/release目录下生成可执行文件,你可以直接运行这个文件:
./target/release/hello_world
以上步骤应该能够帮助你在Debian系统上成功安装和配置Rust编程语言,并搭建一个基本的Rust开发环境。