Updated:Sep 1st, 2024
⬇️ 可以参照下面教程中的步骤,但是存在一些实际的问题,下面会声明:
安装rust
# mac
curl --proto '=https' --tlsv1.2 -sSf <https://sh.rustup.rs> | sh
<aside>
💡 anchor和最新的 rustc
并不兼容,所以需要 rustup
downgrade 一下
</aside>
rustup install 1.79.0
rustup default 1.79.0
安装solana
mac没有配置网络的时候, sh
很难正常工作,建议使用https://docs.solanalabs.com/cli/install中第二种方法 Download Prebuilt Binaries
。
tar jxf solana-release-x86_64-apple-darwin.tar.bz2
cd solana-release/
export PATH=$PWD/bin:$PATH
但是上面并没有加入到全局变量,所以需要把 $PWD
变成自己的工作路径,并且加入到 ~/.zshrc
(如果是zsh)或是 ~/.bashrc
中。工作路径可以打开solana-release下载的路径,在命令行中使用 pwd
获得:
# edit ~/.zshrc
vim ~/.zshrc
# CHANGE YOUR PATH
export PATH=/Users/jason404/Downloads/solana-release/bin:$PATH
<aside> 💡
Updated Mar. 6th, 2025 注意上面的文件是x86,这是为 Intel Mac 设计的,而你的 Mac 是 arm64 架构(Apple Silicon,如 M1/M2)。虽然通过 Rosetta 可以运行 x86_64 程序,但这可能会降低性能,并且可能遇到兼容性问题,尤其是在运行如 solana-test-validator 等需要高性能的命令时。
最近 Solana 的安装脚本更新了,不再支持通过通道(如 stable)直接安装,要求指定具体版本号(如 vX.Y.Z),或从 https://release.anza.xyz 下载。这解释了用户运行 solana-install.sh 时遇到的错误:“Error: No longer supports installation by channel. Please specify a release version as vX.Y.Z or install from https://release.anza.xyz.”
解决方案
使用安装脚本指定版本
访问 Solana Releases 页面,找到最新版本(如 v2.1.13,需确认是否有 arm64 支持)。
运行安装命令:
bash
sh -c "$(curl -sSfL <https://release.anza.xyz/v2.1.13/install>)"
脚本会下载并安装指定版本,完成后提示更新 PATH(如 export PATH="/Users/test/.local/share/solana/install/active_release/bin:$PATH"),将此命令加入 ~/.zshrc 并运行 source ~/.zshrc。 </aside>
安装Anchor: latest
版本似乎还是不兼容,所以可以使用 0.29.0
版本
# download avm
cargo install --git <https://github.com/coral-xyz/anchor> avm --locked --force
# download anchor
# avm install latest (not working)
avm install 0.29.0
# check
anchor --version
Updated:Sep 1st, 2024
solana-keygen new
solana-keygen new --outfile /path/to/your/keypair.json
solana config set --keypair ~/.config/solana/id.json
# localhost
solana config set --url <http://localhost:8899>
# OR devnet
solana config set --url <https://api.devnet.solana.com>
solana config set --url <https://rpc.ankr.com/solana_devnet>
solana config set --url <https://devnet.helius-rpc.com/?api-key=6ac07fca-9101-45c6-b578-21dd764e661b>