paint-brush
Step-by-Step Solana Setup on Windows Using WSLby@hacker-c4zgq42
110 reads

Step-by-Step Solana Setup on Windows Using WSL

by August 14th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This guide walks you through installing and configuring a Solana development environment on Windows using Windows Subsystem for Linux (WSL). It covers setting up WSL, installing Rust and Cargo, Solana CLI, Node.js, Yarn, and VS Code, and configuring the Anchor framework for Solana programming.
featured image - Step-by-Step Solana Setup on Windows Using WSL
undefined HackerNoon profile picture

Anchor the framework for Solana development, currently lacks support for Windows systems. Hence, a Linux environment is required for compatibility with Solana tools and technologies.


This article will guide you through installing Windows Subsystem for Linux (WSL) and other necessary dependencies and technologies, such as Rust, Solana CLI, Node.js, and Yarn, required for Solana development on your Windows system.


Prerequisites

Windows 10+
Good Internet connection
Solana enthusiast


Installations

You will install Windows Subsystem for Linus (WSL), Rust and Cargo, Solana CLI, Node.js, Yarn, and Vs code.

1) Install Windows Subsystem for Linus (WSL)

WSL will allow you to run a Linux environment directly on your Windows system.

Open your Powershell in administrator mode and run this command.

wsl --install


The default wsl distribution, ubuntu, will be installed.

Once installation is complete, restart your machine.

Confirm your WSL version and distribution.

wsl -l -v


You should see this:


Set up your Linux distribution username and password

  1. Go to the search menu on your computer, type Ubuntu, then open it.
  2. You’ll be required to create a username and password. Follow the instructions to do so.

Be sure to save your password somewhere else.


If you run into installation errors or want to install another distribution other than Ubuntu, check WSL's complete installation guide



2) Install Rust and Cargo

Rust is the language for writing Solana programs.

Cargo is a Rust package manager for managing dependencies, building, testing, and deploying Rust codes.


To install Rust and Cargo, run this command on your Ubuntu

curl - proto '=https' - tlsv1.2 -sSf https://sh.rustup.rs | sh


Then, Press 1 or enter to complete the installation

Once installation is complete, confirm your Rust and Cargo version with the following commands

rustc --version

cargo --version



3) Install Solana Cl

To install Solana, run this command on your Ubuntu

sh -c "$(curl -sSfL https://release.solana.com/stable/install)"


After the installation is complete, confirm the Solana version using this command

solana --version



Create your Solana wallet and generate your keypairs.

Create a default Solana wallet, generate your keypairs, and request free devnet tokens for your wallet.

To create your Solana wallet use this command

solana-keygen new


create a passphrase


Ensure to save your public key(a.k.a wallet address) and passphrase(highlighted below in yellow) in a secure location.
Your private key is stored locally on your PC.


Request for devnets to deploy your Solana programs.

To get 10 Solana devnet tokens for your wallet, run this command

Solana airdrop 10

This will send devnet to the default wallet you just created.
To send to a different wallet, useSolana airdrop 10 <wallet address>



4) Install node.js

If you’ve previously installed Node.js on your Windows, you should consider installing Node.js again specifically within your WSL to ensure compatibility.


To Install Node.js using Node Version Manager (NVM)


Run this nvm command on your Ubuntu

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

confirm NVM installation

command -v nvm 

you should see this

Otherwise, close and reopen your Ubuntu and rerun the command.


Install the stable LTS version of Node Js with this command

nvm install - lts

Confirm the installations of Node.js and npm versions

node --version
npm --version



5) Install yarn

yarn official documentation highlighted corepackas one of the two preferred methods of installing Yarn.
npm yarn global installation is not recommended.


To install yarn, enable core pack and initialize a yarn project using the following commands

npm install -g corepack
corepack enable
yarn init

6) Install VS Code

Download VScode directly from the official website

To enable support for the WSL environment in your VSCode, install the WSL extension.

To do so, open VScode, click on the marketplace or “Ctrl + shift + x “, then search for and install the Remote — WSL Extension.

Additionally, install the ‘rust-analyzer’ extension for Rust language support.



7) Install Anchor

Anchor is the Solana framework for writing secure Solana programs.


Install Anchor using Anchor Version Manager (AVM) with this command

cargo install - git https://github.com/coral-xyz/anchor avm - locked - force


Install the latest Anchor version and set it as the default, using the following commands:

avm install latest
avm use latest


Confirm Anchor installation

Anchor –version

If you encounter any installation error check Anchor's official docs



Congratulations 🥳 you are all set to develop on Solana Blockchain