Complete Guide to Setting Up Solana Development on Windows

Share this article:
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:

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:

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:

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:

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

Run the Solana Installation Script

Check Solana CLI Version

Confirm Connection to Solana Cluster

Airdrop SOL to Your Wallet (Devnet)

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:

Follow the On-Screen Instructions

Upon running the above command, you'll be prompted with installation options:

  1. 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
    
  2. Proceed with Default Installation:

    For most users, selecting the default installation is recommended. Type 1 and press Enter.

    1
    
  3. 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:

  1. Using Cargo (Rust’s Package Manager)
  2. 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!