Skip to main content

Command Palette

Search for a command to run...

solana 开发环境搭建

Published
5 min readView as Markdown
C
酷愛計算機技術Ardently Love Computer Technology 長期關註反洗錢反欺詐Long-term Focus on Anti-Money Laundering and Anti-Fraud 精通支付結算的技術、系統、流程和製度Proficient in the Technology, System, Process and Institution of Payment and Settlement
  • 安装 rust
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
...

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish
source $"($nu.home-path)/.cargo/env.nu"  # For nushell

提示设置环境变量。直接查看 rust 版本,报错

# echo $SHELL
/bin/bash
# echo $HOME
/root
# rustc --version
找不到命令 “rustc”,但可以通过以下软件包安装它:
apt install rustc 
apt install rustup

rust 安装位置 root 目录下

# cd /root
# ls -lsirtha
1320637 4.0K drwxrwxr-x  3 root root 4.0K 12月30日 13:30 .cargo
1320654 4.0K drwxrwxr-x  6 root root 4.0K 12月30日 13:31 .rustup

当出现 Rust is installed now. Great 时执行如下命令配置 Rust 环境变量。安装成功

# source $HOME/.cargo/env
# rustc -V
rustc 1.92.0 (ded5c06cf 2025-12-08)
# cargo -V
cargo 1.92.0 (344c4567c 2025-10-21)
  • 安装 nvm

通过 https://www.gitwarp.com/ 加速 github

$ git clone http://gh.halonice.com/https://github.com/nvm-sh/nvm.git
正克隆到 'nvm'...
警告:重定向到 https://gh.halonice.com/https:/github.com/nvm-sh/nvm.git/
remote: Enumerating objects: 9871, done.
remote: Counting objects: 100% (302/302), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 9871 (delta 281), reused 269 (delta 269), pack-reused 9569 (from 3)
接收对象中: 100% (9871/9871), 3.84 MiB | 1.22 MiB/s, 完成.
处理 delta 中: 100% (6355/6355), 完成.

把 nvm 文件夹 复制到 /home/user 目录下,并重命名为 .nvm

在 .bashrc 文件末尾添加命令。并切换为 root 使得环境变量设置生效。安装成功

$ nano .bashrc
$ source .bashrc
bash: [: -R: 需要二元运算符
$ su root
密码: 
# source .bashrc
$ nvm --version
0.40.3
  • nvm 安装 node
$ nvm install v24.12.0
Downloading and installing node v24.12.0...
Downloading https://nodejs.org/dist/v24.12.0/node-v24.12.0-linux-x64.tar.xz...
#############################################################################################################

########################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v24.12.0 (npm v11.6.2)
Creating default alias: default -> v24.12.0

$ nvm ls
->     v24.12.0
default -> v24.12.0
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v24.12.0) (default)
stable -> 24.12 (-> v24.12.0) (default)

$ npm --version
11.6.2
$ node --version
v24.12.0
  • 安装 yarn
# curl -o- -L https://yarnpkg.com/install.sh | bash
# yarn
yarn install v1.22.22
warning package.json: No license field
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package 
managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-
lock.json.
warning No license field
[1/4] Resolving packages...
? (node:6645) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security 

implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
(Use `node --trace-deprecation ...` to show where the warning was created)
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 2.09s.
  • 安装 solana CLI

通过脚本安装;免加速

# sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
downloading stable installer
  ? stable commit 90098d2 initialized
Adding 
export PATH="/root/.local/share/solana/install/active_release/bin:$PATH" to /root/.profile

Close and reopen your terminal to apply the PATH changes or run the following in your existing shell:

export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"

提示设置环境变量,切换为 root 才行

# solana
solana:未找到命令
~/桌面
$ export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
$ solana
solana:未找到命令
$ su root
密码: 
# solana --version
solana-cli 3.0.13 (src:90098d26; feat:3604001754, client:Agave)

成功。每次使用都要设置环境变量,复制粘贴这条命令

  • 安装 avm

通过 cargo 安装。是否需要加速,看运气

# cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
    Updating git repository `https://github.com/coral-xyz/anchor`
    Updating git submodule `https://github.com/openbook-dex/program`
    Updating git submodule `https://github.com/project-serum/stake.git`
    Updating git submodule `https://github.com/project-serum/swap.git`
    Updating git submodule `https://github.com/project-serum/serum-dex.git`
  Installing avm v0.32.1 (https://github.com/coral-xyz/anchor#1cd5c876)
    Updating crates.io index
  Downloaded anstyle-query v1.0.0
...
   Finished `release` profile [optimized] target(s) in 8m 09s
  Installing /root/.cargo/bin/avm
   Installed package `avm v0.32.1 (https://github.com/coral-xyz/anchor#1cd5c876)` (executable `avm`)

# avm --version
avm 0.32.1
  • avm 安装 anchor
# avm --version
avm 0.32.1
# anchor --version
Error: Anchor version not set. Please run `avm use latest`.
# avm use latest
Version 0.32.1 is not installed. Would you like to install? [y/n]
y
Now using anchor version 0.32.1.
# anchor --version
anchor-cli 0.32.1

按照提示,成功

  • 安装 surfpool
# curl -sL https://run.surfpool.run/ | bash

→ Downloading and installing surfpool from http://txtx-public.s3.amazonaws.com/releases/surfpool-linux-x64.tar.gz
→ Installing /root/.local/bin/surfpool
? Install successful

→ Adding /root/.local/bin to your PATH
Added /root/.local/bin to PATH in /root/.bashrc

? PATH updated
   Restart your terminal or run:
     source ~/.bashrc
...
→ Run surfpool start to get started
→ Further documentation: https://docs.surfpool.run
# source ~/.bashrc
# surfpool 1.0.0-rc1
  • 再次确认所有工具都已经安装成功
$ nvm --version
0.40.3
$ su root
密码: 
# npm --version
11.6.2
# node --version
v24.12.0
# yarn --version
1.22.22
# solana --version
solana:未找到命令
# export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
# solana --version
solana-cli 3.0.13 (src:90098d26; feat:3604001754, client:Agave)
# avm --version
avm 0.32.1
# anchor --version
anchor-cli 0.32.1
# surfpool --version
surfpool 1.0.0-rc1

  • 一键安装脚本

有个【一键安装脚本】。根据【Linux 用户须知】提示:先要安装依赖

sudo apt-get update
sudo apt-get install -y build-essential pkg-config libudev-dev llvm libclang-dev protobuf-compiler libssl-dev

curl --proto '=https' --tlsv1.2 -sSfL https://solana-install.solana.workers.dev | bash

无法连接 443 端口,报错

# curl --proto '=https' --tlsv1.2 -sSfL https://solana-install.solana.workers.dev | bash
curl: (7) Failed to connect to solana-install.solana.workers.dev port 443 after 21223 ms: Could not connect to server

浏览器直接访问该域名失败,需要代理。是个脚本文件,可复制粘贴另存 .sh,再 bash 运行

# bash solanainstall.sh 
[INFO] Detected Linux OS.
[INFO] Detected apt-get. Updating package list and installing dependencies...
...
还是有报错
[INFO] Installing Anchor CLI...
    Updating git repository `https://github.com/solana-foundation/anchor`
    Updating git submodule `https://github.com/openbook-dex/program`
    Updating git submodule `https://github.com/project-serum/stake.git`
warning: spurious network error (3 tries remaining): failed to connect to github.com: Connection refused; class=Os (2)
warning: spurious network error (2 tries remaining): SSL error: error:80000020:system library::Broken pipe; class=Net (12)
warning: spurious network error (1 try remaining): SSL error: error:80000020:system library::Broken pipe; class=Net (12)
error: failed to update submodule `examples/cfo/deps/stake`
...
[INFO] Installing Node.js 24.10.0 via NVM...
solanainstall.sh: 行 250: nvm: 未找到命令
solanainstall.sh: 行 251: nvm: 未找到命令
solanainstall.sh: 行 252: nvm: 未找到命令

[INFO] Installing Yarn...
solanainstall.sh: 行 267: npm: 未找到命令
[ERROR] Yarn installation failed.
...
→ Run surfpool start to get started
→ Further documentation: https://docs.surfpool.run
[ERROR] Surfpool installation failed.
[ERROR] Failed to install Surfpool.
[INFO] Appending nvm initialization to /root/.bashrc

最后结果

Installed Versions:
Rust: rustc 1.92.0 (ded5c06cf 2025-12-08)
Solana CLI: solana-cli 3.0.13 (src:90098d26; feat:3604001754, client:Agave)
Anchor CLI: Not installed
Surfpool CLI: Not installed
Node.js: Not installed
Yarn: Not installed

Installation complete. Please restart your terminal to apply all changes.

所以只能改成分项安装

  • 主要参考文章
https://academy.soldevcamp.com/course/solana-program-dev/program-2/

https://developer.aliyun.com/article/1137334

More from this blog

Penetration Test、Python、Weaponization

721 posts

微信 smartcat9999 反欺詐Anti-Fraud 反洗錢Anti-Money Laundering 反逃稅Anti-Tax Evasion 滲透測試Penetration Test 武器化Weaponization