Hello! Welcome to your first lesson in the "Solana Development in 2026" course.
Today, we'll focus on setting up a robust development environment for Rust. This is the foundational step for our entire journey into Solana, as Rust is the primary language for writing Solana programs. By the end of this lesson, you will have installed and configured all the necessary tools to write, compile, and manage Rust code efficiently. We will cover rustup, the Rust toolchain installer; cargo, the build tool and package manager; and rust-analyzer, the language server that supercharges your code editor.
Let's get your machine ready for development.
The Foundation: Your Development Environment
For Solana and Rust development, a Unix-like environment (such as Linux or macOS) is strongly recommended. Since you're on Windows, the best practice is to use the Windows Subsystem for Linux (WSL2). This allows you to run a full Linux distribution directly on Windows, providing seamless compatibility with the entire Solana toolchain and avoiding many common Windows-specific issues.
Your extensive experience with front-end development tools means you're already familiar with the importance of a well-configured environment. Think of WSL2 as creating the ideal operating system layer, much like you'd use specific Node.js versions for different projects.
To get started, let's walk through the WSL2 setup.
Installing All You Need for Solana Development [Solana Basics Tutorial] - Nov 16th '23
This video from Solandy provides a clear, step-by-step guide on installing WSL2 and Ubuntu on a Windows machine. It's tailored specifically for setting up a Solana development environment.
About two and a half minutes in, watch the section Setting up WSL2 for Linux Environment. Follow the instructions to install WSL2 and the Ubuntu distribution. After the reboot and setup, you should have a working Ubuntu terminal.
Once you have completed this step, you will have an Ubuntu terminal. All subsequent commands in this course should be run inside this WSL2/Ubuntu terminal, not in the Windows Command Prompt or PowerShell.
Installing the Rust Toolchain
With your Linux environment ready, the next step is to install Rust itself. We'll use rustup, the official tool for managing Rust versions and associated tools.
rustup installs several key components:
rustc: The Rust compiler.cargo: The Rust build tool and package manager. This is analogous tonpmoryarnin the JavaScript ecosystem. It handles dependencies, builds your project, runs tests, and more.rustfmt: A tool for automatically formatting your code to a standard style.clippy: A powerful linter that catches common mistakes and helps improve your code.- The Rust standard library and offline documentation.
The following resource provides the official instructions for the installation.
The official Visual Studio Code documentation offers a concise guide on installing Rust. We'll focus on the installation and verification steps.
Read the sections '1. Install Rust' for installation instructions and 'Check your installation' to review the verification steps. You will use the command provided for Linux/macOS inside your WSL2 terminal.
To perform the installation, run the command from the guide in your Ubuntu terminal:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Follow the on-screen prompts, and choosing the default option is fine. After installation, make sure to restart your terminal or run the command source "$HOME/.cargo/env" to update your shell's PATH.
To confirm that everything is installed correctly, run these two commands:
rustc --version
cargo --version
You should see the version numbers for the Rust compiler and Cargo printed to the console.
Setting Up Your Code Editor: VS Code and rust-analyzer
As a seasoned developer, you know the value of a good IDE. We will use Visual Studio Code, and the key to making it a first-class Rust development environment is the rust-analyzer extension. This extension provides features like autocompletion, inline error checking, type hints, and code navigation, which are indispensable for productivity.
First, ensure you have VS Code installed on your Windows machine. Then, you'll need to install the WSL extension in VS Code, which allows the desktop application to connect seamlessly to your Linux environment.
The video below walks through installing VS Code and rust-analyzer. Pay close attention to how the editor integrates with the WSL environment you just set up.
Installing All You Need for Solana Development [Solana Basics Tutorial] - Nov 16th '23
This clip from the same Solandy video demonstrates installing VS Code and, crucially, the rust-analyzer extension within the context of the WSL setup.
Starting about seven and a half minutes in, watch the section on installing VS Code and Rust Analyzer, and then jump to the twenty-three-minute mark for the section on verifying its functionality. The first part covers the installation, and the second part shows how to confirm it's working correctly with a project inside WSL.
The core takeaway is that rust-analyzer is not just a syntax highlighter; it's a language server that actively compiles and analyzes your code in the background to provide rich feedback.
To better understand the powerful features you've just enabled, this documentation from the VS Code team provides an excellent overview of what rust-analyzer does.
Skim through the sections on 'IntelliSense', 'Semantic syntax highlighting', 'Linting', 'Quick Fixes', and 'Formatting'. This will give you a solid understanding of the tools now at your disposal.
Test your understanding!
From your front-end experience, you're familiar with tools like ESLint and Prettier. How do the components of the Rust toolchain (clippy and rustfmt) and the rust-analyzer extension map to the roles of those JavaScript tools?
Show answer
clippyis analogous to ESLint. It's a linter that analyzes your code for potential bugs, style issues, and non-idiomatic patterns, going beyond what the basic compiler checks.rustfmtis analogous to Prettier. It's an opinionated code formatter that automatically rewrites your code to conform to a standard style, ensuring consistency across projects.rust-analyzerbundles the functionality of these tools and more into the IDE. It runsclippyandrustfmtfor you, while also providing the core language server features like autocompletion and type inference, similar to how the ESLint or Prettier VS Code extensions integrate those tools directly into your editor.
Creating Your First Rust Project
Let's tie everything together by creating and running a classic "Hello, World!" program using Cargo. This will confirm your entire setup is working correctly.
-
Create a new project: In your WSL2 Ubuntu terminal, navigate to a directory where you want to keep your projects and run:
cargo new hello_worldCargo will create a new directory named
hello_worldcontaining asrcfolder with amain.rsfile and aCargo.tomlfile. -
Open the project in VS Code: From within the
hello_worlddirectory in your terminal, run:code .This command will open the current directory in VS Code. Because you are in a WSL directory, VS Code will automatically use its WSL integration. You can see this in the bottom-left corner of the VS Code window, which should say "WSL: Ubuntu".
-
Explore the project:
Cargo.toml: This is your project's manifest file, similar topackage.json. It contains metadata and dependencies (called "crates" in Rust).src/main.rs: This is the main source file for your binary application.
-
Run the program: Open the integrated terminal in VS Code (Ctrl+`). This will be a WSL terminal. Run the following command:
cargo runCargo will compile and run your program. You should see
Hello, world!printed to the console.
If you see this message, your Rust development environment is successfully configured!
Summary and Next Steps
Congratulations on completing the first lesson! You have successfully:
- Set up a Linux environment on your Windows machine using WSL2.
- Installed the Rust toolchain, including
rustcandcargo, usingrustup. - Configured Visual Studio Code with the
rust-analyzerextension for a powerful IDE experience. - Verified your setup by creating and running your first Rust program with Cargo.
You now have a professional-grade environment that will serve as the foundation for all our future work.
In the next lesson, we will continue our setup by installing the Solana-specific tools, including the Solana CLI and the Anchor framework. This will get us one step closer to writing our first Solana program.
Can't find a good explanation? Sign up and we'll make it for you
Sign up