在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文件生成的项目依赖详细清单。

相关推荐
程序员 _孜然3 小时前
Ubuntu/Debian修改网卡名字enP3p49s0为eth0
linux·运维·驱动开发·嵌入式硬件·ubuntu·debian
IDIOT___IDIOT3 小时前
Linux mount 命令
linux·运维·服务器
暗流者3 小时前
AAA 服务器与 RADIUS 协议笔记
运维·服务器·笔记
锐策3 小时前
Git checkout 与 Git reset 核心区别解析(分支与版本关联逻辑)
运维·git
CTRA王大大4 小时前
【golang】制作linux环境+golang的Dockerfile | 如何下载golang镜像源
linux·开发语言·docker·golang
小张程序人生4 小时前
《VMware 安装 CentOS 7.9 虚拟机详细教程(含图解步骤)》
linux·centos
泡沫冰@6 小时前
管理 SELinux 安全性
linux
展信佳_daydayup8 小时前
03 基础篇-润和开发板连接过程
linux·开源·嵌入式
两张不够花8 小时前
Shell脚本源码安装Redis、MySQL、Mongodb、PostgreSQL(无报错版)
linux·数据库·redis·mysql·mongodb·postgresql·云计算
算力魔方AIPC8 小时前
如何用算力魔方4060安装PaddleOCR MCP 服务器
运维·服务器