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

AWS EC2与DigitalOcean Ubuntu实例安装avm 0.28.0遇libsecp256k1编译错误

问题描述

尝试搭建包含智能合约与客户端的Solana Anchor项目时,在AWS EC2实例及DigitalOcean Ubuntu droplets上执行avm install 0.28.0,出现"cannot compile libsecp256k1 (lib) error"编译错误,但本地Ubuntu环境执行相同命令完全正常。已尝试通过npm包管理器安装Anchor、单独安装libsecp256k1等方案。

已使用的Docker安装配置
# Use an official Node.js runtime as the base image
FROM node:14

# Set a working directory inside the container
WORKDIR /app

# Install necessary dependencies
RUN apt-get update && \
apt-get install -y \
build-essential \
curl \
libssl-dev \
pkg-config \
libsecp256k1-dev \
&& rm -rf /var/lib/apt/lists/*

# Install Rust using the official install script
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init.sh \
&& sh rustup-init.sh -y --default-toolchain stable --profile minimal \
&& rm rustup-init.sh

# Add Rust binaries to PATH
ENV PATH="/root/.cargo/bin:${PATH}"

RUN sh -c "$(curl -sSfL https://release.solana.com/v1.16.7/install)"
ENV PATH="/root/.local/share/solana/install/active_release/bin:$PATH"

RUN cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
RUN avm install 0.28.0
RUN avm use latest
解决方案

1. 补充编译依赖工具

云实例默认依赖可能缺少libsecp256k1编译所需的底层库,修改Dockerfile的apt安装步骤,添加libgmp-dev和clang:

RUN apt-get update && \
apt-get install -y \
build-essential \
curl \
libssl-dev \
pkg-config \
libsecp256k1-dev \
libgmp-dev \
clang \
&& rm -rf /var/lib/apt/lists/*

2. 指定兼容的Rust工具链版本

Anchor 0.28.0对Rust版本有特定要求,默认stable分支可能存在兼容性问题,安装rustup后切换到推荐版本:

# Install Rust using the official install script
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init.sh \
&& sh rustup-init.sh -y --default-toolchain stable --profile minimal \
&& rm rustup-init.sh

# 指定Anchor 0.28.0兼容的Rust版本
RUN rustup toolchain install 1.71.1 && rustup default 1.71.1

3. 直接使用预编译Anchor二进制包

跳过avm编译环节,直接下载官方预编译的二进制文件,避免libsecp256k1编译错误:

# 替换原avm安装相关步骤
RUN curl -sSfL https://github.com/coral-xyz/anchor/releases/download/v0.28.0/anchor-cli-0.28.0-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C /root/.cargo/bin
# 验证版本
RUN anchor --version

4. 匹配Solana与Anchor版本

确认Solana版本与Anchor版本的兼容性,Anchor 0.28.0推荐搭配Solana v1.16.x,若当前v1.16.7仍有问题,可尝试升级到v1.16.15:

RUN sh -c "$(curl -sSfL https://release.solana.com/v1.16.15/install)"
验证方法

修改Dockerfile后重新构建镜像,执行对应命令验证:

  • 若使用avm方案:avm install 0.28.0 && avm use 0.28.0 && anchor --version
  • 若使用预编译方案:anchor --version

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 09:35:05