How to setup Solana in WSL
Setting Up Solana on a Windows Machine
Solana development isn't natively supported on Windows, especially when using frameworks like Anchor. To overcome this, we’ll use Windows Subsystem for Linux (WSL) to create a compatible Linux environment.
This guide walks through the process of setting up a full Solana development environment on your Windows machine using WSL.
Step 1: Install WSL (Windows Subsystem for Linux)
Windows allows you to run a Linux environment directly without dual-booting by using WSL.
Install WSL
-
Open
cmd.exe
in Administrator mode. -
Run the following command:
wsl --install
This installs WSL 2 with the default Ubuntu distribution and enables the required components.
If you’d like to customize the Linux distribution or WSL version, refer to the official Microsoft documentation for WSL installation.
Restart Required
After installation, restart your machine to ensure all components initialize properly.
Step 2: Installing Node.js in Ubuntu
Launch your Ubuntu terminal from the Start Menu. If it fails to open or immediately closes, follow these steps:
Ensure Required Features Are Enabled
-
Open "Turn Windows features on or off".
-
Ensure the following options are enabled:
-
Windows Subsystem for Linux
-
Virtual Machine Platform
-
-
Restart your machine.
Enable Virtualization (if needed)
If Ubuntu still doesn't launch, you may need to enable CPU virtualization in your system BIOS. Refer to your computer manufacturer’s guide for entering the BIOS (usually involves pressing DEL or F2 at boot).
Install Node.js Using NVM
NVM (Node Version Manager) simplifies managing Node.js versions.
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
After installation, restart your terminal and verify NVM is available:
command -v nvm
Then install the latest LTS version of Node.js:
nvm install --lts
Step 3: Install Rust
Solana programs are written in Rust, so you need to install the language and its tools.
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
After installation, confirm the following commands return version numbers:
rustup --version
rustc --version
cargo --version
Step 4: Install Solana CLI
Install the Solana command-line tools:
sh -c "$(curl -sSfL https://release.solana.com/v1.18.11/install)"
If you're prompted to update your PATH environment variable, follow the instructions and add the provided line to your shell configuration file (e.g., .bashrc
, .zshrc
).
Verify the installation:
solana --version
Configure Solana to use your local development cluster:
solana config set --url localhost
solana config get
Expected output should include:
RPC URL: http://localhost:8899
WebSocket URL: ws://localhost:8900/
Step 5: Run a Local Validator
Before running the validator, ensure you're in the home (root) directory of your Ubuntu environment. If you run solana-test-validator
from inside certain project folders (such as an Anchor workspace), the command may fail or behave incorrectly.
Return to your root directory with:
cd ~
Then run the validator:
solana-test-validator
Allow it to start. You’ll see log messages indicating the validator is running and blocks are being produced. This confirms that your local blockchain environment is functioning.
To stop the validator, press:
CTRL + C
You won’t need to run this manually during development—Anchor will handle it for you automatically. This step is simply to confirm the validator is operational.
Step 6: Install Mocha
Mocha is a JavaScript testing framework you’ll use to write and run tests for your Solana programs.
Install it globally:
npm install -g mocha
Summary
You’ve now successfully set up your Solana development environment on Windows using WSL. You should have the following tools working:
-
Ubuntu via WSL 2
-
Node.js with NVM
-
Rust and Cargo
-
Solana CLI tools
-
Local validator
-
Mocha test framework
Important: From now on, run all commands inside the Ubuntu terminal. Avoid using PowerShell or Command Prompt for Solana-related development tasks.
Comments
Post a Comment