Complete Guide to Setting Up Solana Development on Windows

This guide provides a comprehensive walkthrough for setting up a Solana development environment on Windows. It covers the installation of Windows Subsystem for Linux (WSL), Solana CLI, and Rust programming language, which are essential tools for Solana blockchain development.
Step 1: Installing Linux on Windows with WSL
Windows Subsystem for Linux (WSL) allows you to run a Linux environment directly on Windows without needing a virtual machine. This makes developing blockchain applications like those built on Solana easier, as many Solana tools and libraries are Linux-based. In this step, you will enable WSL and install a Linux distribution on your Windows machine.
Open PowerShell as Administrator:
Press Win + X
, then click on Windows PowerShell (Admin) or Terminal (Admin).
Run the Installation Command:
In the PowerShell window, type the following command to install WSL:
wsl --install
This command will:
- Enable the WSL feature.
- Download and install WSL 2.
- Install the default Linux distribution (Ubuntu) from the Microsoft Store.
Restart Your Computer:
After the installation is completed, you may need to restart your machine.
Check the Installation:
Once your computer restarts, open PowerShell and run the following command to check if WSL is installed:
wsl --list --verbose
You should see Ubuntu or another Linux distribution listed as the installed distribution.
Start Using WSL
You can now use your fresh WSL installation. Open PowerShell or your distribution’s terminal to start running Linux commands.
Common Commands to Use WSL:
- Launch the default distribution:
wsl
- List installed distributions:
wsl --list --verbose
- Launch a specific distribution:
Example:wsl -d <distribution name>
wsl -d Ubuntu
- Shutdown WSL:
--shutdown
Step 2: Install Yarn on WSL
Yarn depends on Node.js, so you need to install Node.js first. Here’s how to do it on WSL:
- Update the Package Index:
sudo apt updat
- Install Node.js:
sudo apt install -y nodejs
- Verify Node.js Installation:
node -v npm -v
Now that Node.js is installed, you can install Yarn.
Configure the Yarn APT Repository:
Add the official Yarn repository to your system’s package manager:
- Add GPG Key:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
- Add the Yarn Repository:
cho "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.lis
- Update the Package Index Again
sudo apt update
- Install Yarn:
sudo apt install yarn
- Verify Yarn Installation:
yarn --version
Step 3: Install the Solana CLI
The Solana CLI is an essential tool for interacting with the Solana blockchain, managing wallets, deploying programs, and more.
Open Your WSL Terminal
- Launch your installed Linux distribution (e.g., Ubuntu) from the Start menu or by typing
wsl
in the Command Prompt.
Run the Solana Installation Script
- Execute the following command in your terminal to download and run the Solana installation script:
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"
Check Solana CLI Version
- Run the following command to display the installed Solana CLI version:
Expected Output:solana --version
solana-cli 1.18.8 (src:e2d34d37; feat:3469865029, client:SolanaLabs)
Tip: The version number should correspond to the version you installed (e.g., v1.14.14). If you used the Cargo method, ensure it matches the latest release.
Confirm Connection to Solana Cluster
- Test the CLI by fetching the cluster version:
Expected Output:solana cluster-version
2.0.8
- Alternatively, you can check the current cluster you're connected to:
Sample Output:solana config get
Config File: /home/rakib/.config/solana/cli/config.yml RPC URL: https://api.devnet.solana.com WebSocket URL: wss://api.devnet.solana.com/ (computed) Keypair Path: /home/rakib/.config/solana/id.json Commitment: confirmed
Airdrop SOL to Your Wallet (Devnet)
- Since you're connected to Devnet, you can request an airdrop of SOL for testing purposes:
Sample Output:solana airdrop 2
Requesting airdrop of 2 SOL Signature: 4Pp9R2rorZt1kJ5FoGLXQTv19fsnxqiQs9pgCduiK6K7JczK21JQXwnHXByjJZPrCbqz7JssjbWJrFN6hs8VUmJc 2 SOL
- Verify your balance:
Expected Output:solana balance
2 SOL
Step 4: Install Rust on WSL
Rust is a systems programming language known for its performance and safety, particularly in concurrent programming. In the context of Solana development, Rust is the primary language used to write on-chain programs (smart contracts). Installing Rust correctly is crucial for building, compiling, and deploying Solana programs efficiently. This step-by-step guide will help you install Rust within your WSL (Windows Subsystem for Linux) environment, ensuring a smooth setup for your Solana development projects.
Installing Rust Using Rustup
The recommended method for installing Rust is via rustup, an installer and version management tool for Rust. Rustup allows you to easily install, update, and manage multiple Rust toolchains.
Download and Install Rustup
Open your WSL terminal (e.g., Ubuntu) and execute the following command to download and run the Rustup installation script:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Explanation:
curl
: A command-line tool for transferring data.-proto '=https' --tlsv1.2
: Ensures that the connection uses HTTPS with TLS version 1.2 for security.sSf
: Silent mode with fail and show errors.https://sh.rustup.rs
: The URL for the Rustup installation script.| sh
: Pipes the downloaded script to the shell for execution.
Follow the On-Screen Instructions
Upon running the above command, you'll be prompted with installation options:
-
Choose Installation Type:
Welcome to Rust! This will download and install the official compiler for the Rust programming language, and its package manager, Cargo. ... 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation
-
Proceed with Default Installation:
For most users, selecting the default installation is recommended. Type
1
and press Enter.1
-
Configure PATH Environment Variable:
After installation, Rustup will suggest adding Cargo's bin directory to your
PATH
. To apply the changes immediately, run:source $HOME/.cargo/env
Alternatively, you can close and reopen your terminal.
Verify Rust Installation
To confirm that Rust has been installed correctly, check the versions of rustc
(Rust compiler) and cargo
(Rust package manager):
rustc --version
cargo --version
Expected Output:
rustc 1.81.0 (eeb90cda1 2024-09-04)
cargo 1.81.0 (2dbb1af80 2024-08-20)
Step 5: Install Anchor CLI on WSL
With Rust installed and your development environment primed, the next crucial step in setting up your Solana development environment is installing the Anchor CLI. Anchor is a framework for Solana that streamlines the process of building, testing, and deploying smart contracts (known as programs) on the Solana blockchain. It provides a robust set of tools and abstractions that significantly enhance developer productivity and code safety.
There are two primary methods to install the Anchor CLI:
- Using Cargo (Rust’s Package Manager)
- Using Precompiled Binaries
The recommended method is using Cargo, as it ensures compatibility with your Rust installation and simplifies updates.
Install Anchor Using Cargo
Execute the following command in your WSL terminal to install the Anchor CLI:
cargo install --git https://github.com/coral-xyz/anchor --tag v0.30.1 anchor-cli --locked --force
Note: Replace v0.30.1 with the latest version tag from the Anchor GitHub Releases page. See this issue if installation failed https://github.com/coral-xyz/anchor/issues/3126
Ensure that Anchor CLI is installed correctly by checking its version:
anchor --version
Expected Output:
anchor-cli 0.30.1
Learning Resources
Conclusion
Now that your environment is set up, you can start developing on Solana. A great next step would be to create a "Hello World" Solana program and deploy it on a local cluster or devnet. Happy coding!