在Linux(ubuntu22.04)搭建rust开发环境

1.安装rust

1.安装curl:

sudo apt install curl

2.安装rust最新版

curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

安装完成后出现:Rust is installed now. Great! 重启当前shell即可

3.检验是否安装成功

rustc --version

结果出现:表示rust安装成功。

4.rust更新

rustup update

5.卸载rust

rustup self uninstall

6.安装cargo

sudo apt install cargo

检验是否安装成功,如下图2所示表示安装成功

2.创建第一个rust程序, hello world

1.初识cargo:

Cargo是rust的构建系统和包管理工具,目的就是让不同的人拿到你的包都能直接编译运行,不会因为各种包依赖问题导致程序无法运行。

2.使用cargo:
  1. cargo new hello_world 如下图所示:

2.hello_world初始结构如下图所示:

3.查看main.rs

4.使用cargo运行该程序:cargo run(debug模式:加快编译速度,降低运行速度),结果如下图所示:

cargo run本质是两个步骤:

1.cargo build:编译

2.../target/debug/world_hello:执行可执行程序

3.cargo check:

作用:快速的检查一下代码能否编译通过。

4.cargo.toml和cargo.lock

cargo.toml是cargo特有的项目数据描述文件。

cargo.lock是cargo根据toml文件生成的项目依赖详细清单。

相关推荐
JuiceFS12 小时前
从 MLPerf Storage v2.0 看 AI 训练中的存储性能与扩展能力
运维·后端
CYRUS_STUDIO15 小时前
用 Frida 控制 Android 线程:kill 命令、挂起与恢复全解析
android·linux·逆向
熊猫李17 小时前
rootfs-根文件系统详解
linux
chen94518 小时前
mysql 3节点mgr集群部署
运维·后端
LH_R18 小时前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler19 小时前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
泽泽爱旅行19 小时前
awk 语法解析-前端学习
linux·前端
该用户已不存在1 天前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
大卫小东(Sheldon)2 天前
写了一个BBP算法的实现库,欢迎讨论
数学·rust
少妇的美梦2 天前
logstash教程
运维