You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Solana合约开发环境搭建及cargo build-sbf报错求助

Solana合约编译报错(rustc版本不兼容+solana-install命令缺失)

环境信息

  • 系统:Ubuntu 24.04.1
  • solana-cli版本:2.2.3 (src:0b37b8fd; feat:3294202862, client:Agave)
  • cargo版本:1.85.1 (d73d2caf9 2024-12-31)

报错场景

使用最简测试合约代码执行cargo build-sbf时,报错:

info: uninstalling toolchain 'solana' info: toolchain 'solana'
uninstalled error: rustc 1.79.0-dev is not supported by the following
package:

Note that this is the rustc version that ships with Solana tools and
not your system's rustc version. Use solana-install update or head
over to https://docs.solanalabs.com/cli/install to install a newer
version. bytemuck_derive@1.9.2 requires rustc 1.84 Either upgrade
rustc or select compatible dependency versions with cargo update <name>@<current-ver> --precise <compatible-ver> where
<compatible-ver> is the latest version supporting rustc 1.79.0-dev

同时执行solana-install update提示命令未找到。

可行解决步骤

1. 修复solana-install命令缺失

  • 若通过官方脚本安装的Solana CLI,重新执行安装脚本并加载环境变量:
    curl -sSf https://release.solana.com/v2.2.3/install | sh
    source ~/.profile
    
  • 若通过cargo安装的Solana CLI,先卸载再用官方脚本重装:
    cargo uninstall solana-cli
    curl -sSf https://release.solana.com/v2.2.3/install | sh
    source ~/.profile
    

2. 升级Solana CLI到兼容版本

Solana 2.2.3自带的rustc 1.79.0-dev低于依赖要求的1.84,需升级CLI版本:

  • 环境变量加载完成后,执行:
    solana-install update
    
  • 若上述命令仍失败,直接指定更高版本安装(如v2.6.0,需确保自带rustc≥1.84):
    curl -sSf https://release.solana.com/v2.6.0/install | sh
    source ~/.profile
    

3. 降级依赖规避版本冲突(临时方案)

若暂时无法升级Solana CLI,可锁定bytemuck_derive到兼容rustc 1.79.0-dev的版本:

  • 修改Cargo.toml的依赖部分:
    [dependencies]
    solana-program = "=2.1.16"
    bytemuck_derive = "=1.6.0"
    
  • 执行更新命令后重新编译:
    cargo update
    cargo build-sbf
    

4. 验证环境一致性

执行以下命令确认版本匹配:

solana --version
solana rustc --version

内容的提问来源于stack exchange,提问作者Matthew Cornelisse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 17:45:10