How to Setup the Solana Development Environment

Introduction

A strong development setup is super important for building stuff on Solana. When you set it up right, it makes everything smoother. Plus, it makes sure your tools work well with Solana's system, so you can easily use them to create and launch your smart contracts and apps. Having the right setup also gives you all the tools you need to test and try out your ideas quickly. By getting to know Solana's system and how to work with it, you can make cool stuff for lots of different things, like finance or unique digital items.

If you are new to Solana, I recommend you the following article to know what is Solana and why you use Solana?

solana-setup

We can install Solana on three operating systems Windows(WSL), Linux, and MacOS. For now, we will use Windows(WSL).

Install WSL

WSL, or Windows Subsystem for Linux, is a compatibility layer for Windows that enables you to run Linux distributions directly on your Windows machine. It allows developers to use Linux tools, utilities, and command-line interfaces on a Windows environment without the need for virtual machines or dual-booting. In the context of Solana development, WSL is often used to create a Linux-like environment on Windows systems, providing seamless compatibility with Solana's tooling and libraries.

For running the Solana in Windows we need to install WSL in your machine. Follow this article to install WSL.

Install Rust

Rust is a programming language known for its speed, reliability, and safety features. It's popular in the development of blockchain projects like Solana because it allows developers to write efficient and secure code. In the context of setting up a Solana development environment, Rust is used to write smart contracts that run on the Solana blockchain. It's a key tool in building decentralized applications on Solana.

We need to install Rust as we write our programs in the Rust language. To install Rust in your system first open the WSL terminal then paste the following command.

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

So we have installed the Rust successfully. Now restart your terminal or run the following command to refresh your new path setting.

source ~/.bashrc

Run the following command to check whether Rust is installed or not.

rustc --version

Install Solana CLI

Solana CLI is like a toolbox for working with Solana. It's a set of commands you can use in your computer's terminal to do all sorts of things on the Solana blockchain. You can create new projects, deploy smart contracts, send transactions, and much more, all from the command line. It's the main way developers interact with Solana's system directly from their computers.

Run the following command in your terminal to install Solana CLI

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

You have the option to substitute "stable" with the release tag that corresponds to the software version you want (such as v1.18.1), or you can opt for one of the three symbolic channel names: stable, beta, or edge.

Now run the following command to check the version of Solana.

solana --version

Output

solana-cli 1.17.25 (src:d0ed878d; feat:3580551090, client:SolanaLabs)

We have successfully installed the Solana CLI, Let's move to the next step by installing the 'Anchor' framework.

Install Anchor

To set up and maintain different versions of the Anchor framework, we'll use AVM, the Anchor Version Manager. Because AVM is installed through cargo (Rust's package manager), the installation process remains consistent across all operating systems. Once installed, AVM enables us to easily install the specific version of the Anchor framework we need.

Install AVM

Run the following command in your terminal to install avm.

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

Install Anchor using avm

Restart your terminal and run the following command to install Anchor.

avm install latest
avm use latest

Setup a localhost blockchain cluster

The Solana CLI includes a built-in test validator, enabling you to run a complete blockchain cluster directly from your command line interface.

Now open a new tab of the terminal and run the following command to run the localhost cluster.

solana-test-validator

Now return to the first terminal tab and configure the Solana CLI with the local cluster by running the following command.

solana config set --url localhost

To view the configuration of the Solana cli run the following command.

solana config get

Create a file system wallet

In Solana, a file system wallet is like a digital wallet that lives on your computer. It's a secure place where you can keep your Solana cryptocurrency and interact with the Solana blockchain. Instead of relying on a third-party service, like an online wallet, a file system wallet stores your cryptocurrency keys directly on your device. This gives you more control and security over your funds. You can use your file system wallet to send and receive Solana tokens, participate in decentralized finance (DeFi) activities, and more, all from your computer. It's an essential tool for anyone looking to engage with the Solana ecosystem.

Let's create a file system wallet to use during the development. Run the following command in the terminal.

solana-keygen new

The solana-keygen command automatically generates a new file system wallet, which is initially saved at ~/.config/solana/id.json. You have the option to specify a different location for the output file by using the --outfile /path option.

Set your new wallet as the default

Run the following command to set the wallet as default.

solana config set -k ~/.config/solana/id.json

Airdrop SOL token in your wallet

After setting a new wallet as default, you can request a free SOL token by running the following command.

solana airdrop 2

Now check the current balance in your wallet.

solana balance

Conclusion

Setting up your Solana development environment is the gateway to seamless and efficient blockchain development. With the right tools in place, you can navigate Solana's ecosystem with ease, empowering you to create and launch smart contracts and applications effortlessly. Stay tuned for more insights and tutorials as we dive deeper into writing Rust programs, understanding the Anchor framework, and deploying your programs on the Solana blockchain.