Installation
This section covers the steps to set up your local environment for Solana development.
Quick Installation
On Mac and Linux, run this single command to install all dependencies.
Windows users: Install WSL (see Install Dependencies), then run the command above in the Ubuntu (Linux) terminal.
After installation, you should see output similar to the following:
If the quick installation command above doesn't work, please refer to the Install Dependencies section below for instructions to install each dependency individually.
Install Dependencies
The instructions below will guide you through installing each dependency individually.
- Windows users must first install WSL (Windows subsystem for Linux) and then install the dependencies specified in the Linux section below.
- Linux users should first install the dependencies specified in the Linux section below.
- Mac users should start with the Rust installation instructions below.
Install Rust
Solana programs are written in the Rust programming language.
The recommended installation method for Rust is rustup.
Run the following command to install Rust:
You should see the following message after the installation completes:
Run the following command to reload your PATH environment variable to include Cargo's bin directory:
To verify that the installation was successful, check the Rust version:
You should see output similar to the following:
Install the Solana CLI
The Solana CLI provides all the tools required to build and deploy Solana programs.
Install the Solana CLI tool suite using the official install command:
You can replace stable
with the release tag matching the software version of
your desired release (i.e. v2.0.3
), or use one of the three symbolic channel
names: stable
, beta
, or edge
.
If it is your first time installing the Solana CLI, you may see the following
message prompting you to add a PATH
environment variable:
If you are using a Linux or WSL terminal, you can add the PATH
environment
variable to your shell configuration file by running the command logged from the
installation or by restarting your terminal.
To verify that the installation was successful, check the Solana CLI version:
You should see output similar to the following:
You can view all available versions on the Agave Github repo.
Agave is the validator client from Anza, formerly known as Solana Labs validator client.
To later update the Solana CLI to the latest version, you can use the following command:
Install Anchor CLI
Anchor is a framework for developing Solana programs. The Anchor framework leverages Rust macros to simplify the process of writing Solana programs.
There are two ways to install the Anchor CLI and tooling:
- Anchor Version Manager (AVM) - Recommended installation method
- Without AVM - Install directly from GitHub
The Anchor version manager (AVM) allows you to install and manage different Anchor versions on your system and easily update Anchor versions in the future.
Install AVM with the following command:
Check that AVM was installed successfully:
Install the latest version of Anchor CLI using AVM:
Alternatively, you can install a specific version of Anchor CLI by specifying the version number:
Don't forget to run the avm use
command to declare which Anchor CLI version
should be used on your system.
- If you installed the
latest
version, runavm use latest
. - If you installed the version
0.30.1
, runavm use 0.30.1
.
To verify that the installation was successful, check the Anchor CLI version:
You should see output similar to the following:
When installing the Anchor CLI on Linux or WSL, you may encounter this error:
If you see this error message, follow these steps:
- Install the dependencies listed in the Linux section at the top of this page.
- Retry installing the Anchor CLI.
Node.js and Yarn
Node.js and Yarn are required to run the default Anchor project test file
(TypeScript) created with the anchor init
command. (Rust test template is also
available using anchor init --test-template rust
)
When running anchor build
, if you encounter the following errors:
After applying the solution above, attempt to run anchor build
again.
When running anchor test
after creating a new Anchor project on Linux or WSL,
you may encounter the following errors if Node.js or Yarn are not installed:
Solana CLI Basics
This section will walk through some common Solana CLI commands to get you started.
Solana Config
To see your current config:
You should see output similar to the following:
The RPC URL and Websocket URL specify the Solana cluster the CLI will make requests to. By default this will be mainnet-beta.
You can update the Solana CLI cluster using the following commands:
You can also use the following short options:
The Keypair Path points to the default Solana wallet (keypair) used by the
Solana CLI to pay transaction fees and deploy programs. By default, this file is
stored at ~/.config/solana/id.json
.
Create Wallet
To send transactions using the Solana CLI, you need a Solana wallet funded with SOL.
To generate a keypair at the default Keypair Path, run the following command:
You should see output similar to the following:
If you already have a file system wallet saved at the default location, this
command will NOT override it unless you explicitly force override using the
--force
flag.
To view your wallet's address (public key), run:
Airdrop SOL
Request an airdrop of SOL to your wallet to pay for transactions and program deployments.
Set your cluster to the devnet:
Then request an airdrop of devnet SOL:
Devnet airdrops are limited to 5 SOL per request. If you hit rate limits or encounter errors, try using the Web Faucet instead.
To check your wallet's SOL balance, run the following command:
Run Local Validator
The Solana CLI includes a built-in test validator for local development.
In a separate terminal, run the following command to start a local validator:
Remember to update your CLI to use localhost before running any commands:
Anchor CLI Basics
This section will walk through some common Anchor CLI commands to get you started. For more information on the Anchor CLI, see the Anchor documentation.
Initialize Project
To create a new Anchor project, run the following command:
For example, to create a project called my-project
, run:
This command creates a new directory with the project name and initializes a new Anchor project with a basic Rust program and TypeScript test template.
Navigate to the project directory:
See the Anchor project's file structure.
Build Program
To build your project, run the following command:
The compiled program can be found in the /target/deploy
directory.
Deploy Program
To deploy your project, run the following command:
This command will deploy your program to the cluster
specified in the
Anchor.toml
file.
Test Program
To test your project, run the following command:
This command builds, deploys, and runs the tests for your project.
When using localnet
as the cluster
in Anchor.toml
, Anchor automatically
starts a local validator, deploys your program, runs tests, and then stops the
validator.