阅读量:2
在Debian系统上使用Rust可以分为以下几个步骤:
安装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管理Rust项目
- 创建一个新的Rust项目:
cargo new hello_world
cd hello_world
- 编写Rust代码:
使用文本编辑器打开
src/main.rs文件,并输入以下代码:
fn main() {
println!("Hello, world!");
}
- 编译并运行Rust程序:
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开发环境。
以上就是关于“Rust在Debian上怎么用”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm