debian

Rust在Debian上如何配置环境

小樊
46
2025-08-10 01:09:00
栏目: 编程语言

在Debian上配置Rust环境步骤如下:

  1. 更新系统并安装依赖包

    sudo apt update  
    sudo apt install curl build-essential gcc make -y  
    
  2. 使用rustup安装Rust

    wget -qO - https://sh.rustup.rs | sudo bash -s -- --no-modify-path -y  
    

    (安装到/opt/rust目录,避免修改系统路径)

  3. 配置环境变量

    echo 'export RUSTUP_HOME=/opt/rust' | sudo tee -a /etc/profile.d/rust.sh  
    echo 'export PATH=$PATH:/opt/rust/bin' | sudo tee -a /etc/profile.d/rust.sh  
    source /etc/profile  
    

    验证:echo $RUSTUP_HOMEecho $PATH确认路径正确。

  4. 验证安装

    rustc --version  # 查看Rust编译器版本  
    cargo --version  # 查看包管理器版本  
    
  5. (可选)配置工具链补全

    rustup completions bash > /usr/share/bash-completion/completions/rustup  
    source /etc/profile.d/bash_completion.sh  
    
  6. (可选)配置国内镜像加速
    编辑~/.cargo/config.toml,添加:

    [source.crates-io]  
    replace-with = "tuna"  
    [source.tuna]  
    registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"  
    

完成以上步骤后,即可使用cargo创建、构建Rust项目。如需打包为Debian包,可安装cargo-deb工具:cargo install cargo-deb

0
看了该问题的人还看了